python - matplotlib bug in plot_dates? -


just wanted see if others thought following behaviour in matplotlib plot_date buggy, or if it's should put with.

i have multi-panel plot set sharex facilitate zoom/pan on axes, , plot time series data in both panels. however, in second panel, of data happens invalid (in example mask it).

from matplotlib.pyplot import figure,show datetime import datetime,timedelta 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 seconds xdata=linspace(0,9999,10000) tdata=array([datetime(2000,1,1)+timedelta(seconds=ss) 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) show blank panel, not fail , give me long unhelpful traceback. expected behaviour?

notes:

  • this script fails if use ax.plot(...) instead of ax.plot_date(...)
  • it works fine (i.e. gives me empty panel) if plot against xdata, not datetime array tsdata (but have use ax1.set_xlim(xdata[0],xdata[-1]) 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 realised can rescue above plot forcing ax2 limits right before show() command. still think failure in main example inelegant:
   ax2.set_xlim(tdata[0],tdata[-1])    show() 

what experts think?

thanks!

f.y.i., on matplotlib 1.1.0, compiled source on pc.

here traceback 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 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 >= 1 
if suspect ipython bug, please report at: https://github.com/ipython/ipython/issues or send email mailing list @ ipython-dev@scipy.org 

yes, call bug, or @ least oversight looks has been fixed (via @ali_m https://github.com/matplotlib/matplotlib/issues/162).

i getting exception, on version of 1.3.x june (my bad, thought had more current version on computer). current master not have problem , @ali_m reports works on 1.2.1 , 1.3.0 suspect fix upgrade version of matplotlib.

what looks going on there isn't check in code sorts out where put ticks has no check make sure have given in non-empty data.

the reason setting limits explicitly prevents error code never tries figure out range of empty data is.

please create github issue (and include trace in issue).

in [7]: traceback (most recent call last):   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/backends/backend_qt4.py", line 366, in idle_draw     self.draw()   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/backends/backend_qt4agg.py", line 148, in draw     figurecanvasagg.draw(self)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/backends/backend_agg.py", line 440, in draw     self.figure.draw(self.renderer)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper     draw(artist, renderer, *args, **kwargs)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 1027, in draw     func(*args)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper     draw(artist, renderer, *args, **kwargs)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/axes.py", line 2088, in draw     a.draw(renderer)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper     draw(artist, renderer, *args, **kwargs)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/axis.py", line 1076, in draw     ticks_to_draw = self._update_ticks(renderer)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/axis.py", line 938, in _update_ticks     tick_tups = [t t in self.iter_ticks()]   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/axis.py", line 882, in iter_ticks     majorlocs = self.major.locator()   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 785, in __call__     self.refresh()   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 794, in refresh     dmin, dmax = self.viewlim_to_dt()   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 560, in viewlim_to_dt     return num2date(vmin, self.tz), num2date(vmax, self.tz)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 305, in num2date     return _from_ordinalf(x, tz)   file "/home/tcaswell/local_installs/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 208, in _from_ordinalf     dt = datetime.datetime.fromordinal(ix) valueerror: ordinal must >= 1 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -