I've got an MPL widget embedded in a qt application. The user interacts w/
the GUI and causes data to be shown or hidden in the plot. Since the data
can be very large (5-10 lines w/ 40,000 points in each), I've written code
that reads the data and builds Line2D objects. Then I call axes.add_line()
and line.remove() to add and remove them from my plot.
This works fine when the x axis is a floating point axis. If I switch the x
axis to dates, then when I try to re-add some removed lines, I get the error
at the bottom of the email. A script that duplicates this is attached
(though I think you need to have an interactive mode session running to
really see what happens.
As an example:
1) read data and build 4 Line2D objects
2) user shows lines 1 and 2
3) user hides lines 1 and 2, shows lines 3 and 4
4) user hides lines 3 and 4, shows lines 1 and 2
These steps work fine w/ floats. But if I tell the xaxis to be date
(axis.xaxis_date()), then step 4 above will give the error:
File "./error.py", line 62, in <module>
run( True )
File "./error.py", line 53, in run
ax.autoscale_view()
File
"/group/monte/development/rh8/tools.2007_03_13/lib/python2.5/site-packages/m
atplotlib/axes.py", line 1268, in autoscale_view
XL = self.xaxis.get_major_locator().autoscale()
File
"/group/monte/development/rh8/tools.2007_03_13/lib/python2.5/site-packages/m
atplotlib/dates.py", line 568, in autoscale
dmin, dmax = self.datalim_to_dt()
File
"/group/monte/development/rh8/tools.2007_03_13/lib/python2.5/site-packages/m
atplotlib/dates.py", line 434, in datalim_to_dt
return num2date(dmin, self.tz), num2date(dmax, self.tz)
File
"/group/monte/development/rh8/tools.2007_03_13/lib/python2.5/site-packages/m
atplotlib/dates.py", line 234, in num2date
if not cbook.iterable(x): return _from_ordinalf(x, tz)
File
"/group/monte/development/rh8/tools.2007_03_13/lib/python2.5/site-packages/m
atplotlib/dates.py", line 157, in _from_ordinalf
dt = datetime.datetime.fromordinal(ix)
ValueError: ordinal must be >= 1
Any help would be greatly appreciated. It almost seems like using date mode
is somehow changing the Line2D object. I tried not clearing the figure and
just removing the lines, but that causes other problems (the plot won't
autoscale in step 4 and I also need to toggle other items on and off -
legends and things).
Thanks,
Ted
error.py (1.07 KB)