python - Pandas graphing a timeseries, with vertical lines at selected dates -


consider timeseries, cumulative number of edits in wikipedia category.

in [555]: cum_edits.head() out[555]: 2001-08-31 23:37:28    1 2001-09-01 05:09:28    2 2001-09-18 10:01:17    3 2001-10-27 06:52:45    4 2001-10-27 07:01:45    5 name: edits, dtype: int64 in [565]: cum_edits.tail() out[565]: 2014-01-29 16:05:15    53254 2014-01-29 16:07:09    53255 2014-01-29 16:11:43    53256 2014-01-29 18:09:44    53257 2014-01-29 18:12:09    53258 name: edits, dtype: int64 

i have graph so:

in [567]:  cum_edits.plot()  out[567]:  <matplotlib.axes.axessubplot @ 0x1359c810> 

cummulative edits

i plot vertical lines, after every total_edits/n ; e.g. n=10 edits. calculate these easily.

in [568]:  dates  out[568]:  [timestamp('2006-06-04 04:46:22', tz=none),  timestamp('2007-01-28 23:53:02', tz=none),  timestamp('2007-09-16 10:52:02', tz=none),  timestamp('2008-04-28 21:20:40', tz=none),  timestamp('2009-04-12 22:07:13', tz=none),  timestamp('2010-04-09 18:45:37', tz=none),  timestamp('2011-03-28 23:38:12', tz=none),  timestamp('2012-05-24 13:44:35', tz=none),  timestamp('2013-03-05 17:57:29', tz=none),  timestamp('2014-01-29 16:05:15', tz=none)] 

normally 1 can use axvline() although encounter 2 problems. if call plt.axvline(x=0.5, color='r') produce arbitrary line, not see on top of pandas plot. using ipython %pylab inline way. , secondly, not how translate dates x position being used in cum_edits.plot() since translation invisible me. should go producing these vertical lines?

thanks @tomaugspurger

the solution axes back, , use ax.vlines.

ax = cum_edits.plot() ymin, ymax = ax.get_ylim() ax.vlines(x=dates, ymin=ymin, ymax=ymax-1, color='r') 

solutions vlines

one last niggle if vlines ymax long, matplotlib adds space top of plot, reduce length less original axes, why see ymax=ymax-1.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -