|
From: Mike K. <mc...@gm...> - 2012-10-09 03:46:05
|
On 10/8/12 11:03 PM, Paul Tremblay wrote: > I often have to make graphs with time series, with each point being the > start of a week. Below is the result I wish: > > However, in order to make the secondary x axis the the month labels, I > need something like 40 lines of code. My strategy consists in first > drawing the rates in the normal way and using matplotlib's dateFormatter > to set the week numbers. That part is easy. > > In order to draw the x axis below to show when the weeks occur, I draw > two more lines, and makes these lines invisible. The first line has as > the x points the start of each month, and the y values as the > corresponding rate. The second line has as its x value the middle of > each month, with the corresponding y value. > > Below is my code. I have to use such a graph quite often--so often, in > fact, that if I don't find an easier way to make the secondary x axis, I > will store the code in my own library for re-use. Does anyone know of a > simpler, more elegant way? > Don't have time to prove that I can reproduce what you want, but try parasite axes with axes_grid1: the example is for one on the right-hand side, but I think it'll do what you want. http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axisartist-with-parasiteaxes M |