Hi Gang, Thank you guys, and thanks for the Wiki entry
> Andrea.
> I have a further small question. When I add a line to my
> plot, the axes gracefully rescale to accomodate the new
> data plotted. However, when I remove a line, they do not
> rescale, even if I call:
> locator = self.leftaxis.yaxis.get_major_locator()
> locator.autoscale()
> Or:
> self.leftaxis.autoscale_view(scalex=False, scaley=True)
> I also call self.canvas.draw(), self.Refresh()... nothing
> happens. Is there a way to make the axes rescale after
> removing a line from a plot?
The Axes instance has two BBox (bounding box) instances -- the dataLim
and the viewLim. The dataLim store a rectangle that bounds all the
data in the Axes, and the viewLim are the x and y view limits, ie,
xlim and ylim. Autoscaling sets the viewLim based on the dataLim.
When you add lines to the plot, the dataLim are updated, but when you
remove data with del ax.lines[-1] etc, the dataLim are not updated.
If all you have in the Axes are line instances, you can update the
dataLim with the remaining lines, but first you must tell it to ignore
it's current limits. You do this with the ignore flag
# after removing a line, do
ignore = True
for line in ax.lines:
x = line.get_xdata()
y = line.get_ydata()
ax.dataLim.update_numerix(x, y, ignore)
ignore = False
If you have other data in your Axes, eg Polygons or Collections, it is
a bit more complicated. It would be useful to have an Axes method
like "auto_datalim" to for the datalim to readjust to all the current
data.
After you have tested this, would you mind updating the wiki with this
information?
Thanks,
JDH