Hi, all
I found a problem about xlim. It sometimes changes when there is no explicit
calling of set_xlim.
My application scenario is : at some situation replot the second one of two
subplots, which shares x axis with the first one. To finish the replot
operation, i first use clear() method to remove the previous image, and then
plot a new one. The problem is that, there is an 'unexpected' change of
xlim.
The attached code is tried to reproduce the problem. I'm sorry for that it
is not small enough and that it even seems ugly. But after all, the problem
can be showed by it. Its text output simply shows the 'unexpected' changes.
As it can be seen, plot operation causes change of xlim. While, i'd like to
see that xlim changes only when responding to call ing set_xlim().
What's the possible reason? How should i do to avoid the unexpected
change? As the sample code shows, the unexpected change can be reverted by
calling set_xlim(). but this solution doesn't seem a graceful one.
Thank you for your any help.
--
sunzen
<<freedom & enjoyment>>
#!/usr/bin/env python
#
#
import gtk
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar
from matplotlib.numerix import *
from matplotlib.ticker import FuncFormatter
class BaseView(FigureCanvas):
def __init__(self, numgraphs = 2):
self.axlist = []
self.fig = Figure()
self.axlist.append(self.fig.add_subplot(numgraphs, 1 ,1))
for i in range(2, numgraphs + 1):
self.axlist.append(self.fig.add_subplot(numgraphs, 1 ,i, sharex = self.axlist[0],autoscale_on = False))
FigureCanvas.__init__(self, self.fig)
for ax in self.axlist:
self.set_formatter(ax)
def set_formatter(self,ax):
def formatter_b(x, pos = None):
nano = long(x)
return str(nano)
xmajorFormatter = FuncFormatter(formatter_b)
axis = ax.get_xaxis()
axis.set_major_formatter(xmajorFormatter)
class ViewOne(BaseView):
def __init__(self):
dxlim = (0,3797217271)
BaseView.__init__(self, numgraphs = 2)
self.axlist[0].set_xlim(dxlim)
xlim = self.axlist[0].get_xlim()
print "initial xlim ", xlim
self.axlist[1].set_ylim(0,3)
ts = (0, 200, 3000, 400000, 3000000000,3797217271)
y1 = (1, 1, 1,1,1,1)
y2 = (0,1,1,1,0,1)
self.axlist[0].plot(ts,y1,picker = 5)
self.axlist[1].plot(ts,y2,picker = 5)
xlim = self.axlist[0].get_xlim()
print "xlim after plotting", xlim
if xlim != dxlim:
self.axlist[1].set_xlim(dxlim)
print "reset xlim for plotting causes change"
def replot_ax2(self):
self.axlist[1].clear()
dxlim = (0,3797217271)
xlim = self.axlist[1].get_xlim()
print "xlim after clear operation", xlim
if xlim != dxlim:
self.axlist[1].set_xlim(dxlim)
print "reset xlim for clear causes change? "
ts = (0, 200, 3000, 400000, 3000000000,3797217271)
y1 = (1, 2, 1,2,1,2)
self.set_formatter(self.axlist[1])
self.axlist[1].plot(ts,y1,picker = 5)
xlim = self.axlist[0].get_xlim()
print "xlim after replotting", xlim
if xlim != dxlim:
self.axlist[1].set_xlim(dxlim)
print "reset xlim for replotting causes change"
self.draw()
class testapp():
def __init__(self):
self.window = gtk.Window()
self.window.set_default_size(800,600)
self.nb = gtk.Notebook()
self.window.add(self.nb)
self.vbox = gtk.VBox()
self.view = ViewOne()
self.vbox.pack_start(self.view, True, True, 0)
navbar = NavigationToolbar(self.view, self.window)
self.vbox.pack_start(navbar, False, False,0)
self.nb_label0 = gtk.Label("page0")
self.nb.append_page(self.vbox,self.nb_label0)
self.view.mpl_connect('pick_event', self.onpick)
def main(self):
self.window.show_all()
gtk.main()
def onpick(self,event):
picked_axes = event.mouseevent.inaxes
if picked_axes == self.view.axlist[0]:
pass
else:
self.view.replot_ax2()
if __name__ == "__main__":
app = testapp()
app.main()
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users