Just wanted to see if others thought that the following behaviour in matplotlib plot_date was buggy, or if it's just something I should put up with.
I have a multi-panel plot that I set up with sharex to facilitate zoom/pan on all axes, and I plot time series data in both panels. However, in the second panel, all of the data happens to be invalid (in this example I mask it).
from matplotlib.pyplot import figure,show
from datetime import datetime,timedelta
from numpy import sin,cos,linspace,pi,ma,array
fig=figure(figsize=(16,9))
ax1=fig.add_subplot(211)
ax2=fig.add_subplot(212,sharex=ax1)
# xdata is seconds
xdata=linspace(0,9999,10000)
tdata=array([datetime(2000,1,1)+timedelta(seconds=ss) for ss in xdata])
data1=ma.masked_array(sin(pi*xdata/300),mask=False)
data2=ma.masked_array(cos(pi*xdata/300),mask=True)
ax1.plot_date(tdata,data1,marker='',color='r')
ax2.plot_date(tdata,data2,marker='',color='b')
show()
I'd expect (prefer) it to just show up a blank panel, not to fail and give me a long unhelpful traceback. Is this the expected behaviour?
Notes:
- This script also fails if I use
ax.plot(...)instead ofax.plot_date(...) - It works fine (i.e. gives me an empty panel) if I just plot against
xdata, not the datetime arraytsdata(but I have to useax1.set_xlim(xdata[0],xdata[-1])to get a sensible domain displayed):
ax1.plot(xdata,data1,marker='',color='r') ax2.plot(xdata,data2,marker='',color='b') ax1.set_xlim(xdata[0],xdata[-1]) show()
- I have just realised I can rescue the above plot by forcing the
ax2limits right before theshow()command. I still think that the failure in the main example is inelegant:
ax2.set_xlim(tdata[0],tdata[-1]) show()
What do the experts think?
Thanks!
F.Y.I., This was on matplotlib 1.1.0, compiled from source on my PC.
Here is the traceback that I get:
Traceback (most recent call last):
File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/backendsbackend_gtk.py", line 395, in expose_even self._render_figure(self._pixmap, w, h) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 75, in _render_f FigureCanvasAgg.draw(self) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 401, in draw self.figure.draw(self.renderer) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/figure.py", line 884, in draw func(*args) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/axes.py", line 1983, in draw a.draw(renderer) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/axis.py", line 1036, in draw ticks_to_draw = self._update_ticks(renderer) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/axis.py", line 926, in _update_ticks tick_tups = [ t for t in self.iter_ticks()] File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/axis.py", line 873, in iter_ticks majorLocs = self.major.locator() File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/dates.py", line 749, in __call__ self.refresh() File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/dates.py", line 758, in refresh dmin, dmax = self.viewlim_to_dt() File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/dates.py", line 530, in viewlim_to_dt return num2date(vmin, self.tz), num2date(vmax, self.tz) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/dates.py", line 289, in num2date if not cbook.iterable(x): return _from_ordinalf(x, tz) File "/home/tchubb/local/lib/python2.7/site-packages/matplotlib/dates.py", line 203, in _from_ordinalf dt = datetime.datetime.fromordinal(ix) ValueError: ordinal must be >= 1
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]