On Thu, Jul 22, 2010 at 3:30 AM, aliko <ali.tli...@gmail.com> wrote:

> Could please anyone help me to get axises autoscaling in following
> example? I took it from the examples and slightly modified it to remove
> all unecessary things trying to make it as short as possible.
>
> Thanks in advance!
>
> import sys
>
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
> FigureCanvas
>
> from PyQt4 import QtGui
>
> import numpy as np
> import time
>
> class BlitQT(FigureCanvas):
>     def __init__(self):
>         FigureCanvas.__init__(self, Figure())
>
>         self.ax = self.figure.add_subplot(111)
>         self.ax.grid()
>         self.draw()
>
>         self.ax_background = self.copy_from_bbox(self.ax.bbox)
>         self.cnt = 0
>
>         self.x = np.arange(0,2*np.pi,0.01)
>         self.sin_line, = self.ax.plot(self.x, np.sin(self.x),
> animated=True)
>         self.cos_line, = self.ax.plot(self.x, np.cos(self.x),
> animated=True)
>
>         self.tstart = time.time()
>         self.startTimer(10)
>
>     def timerEvent(self, evt):
>         self.restore_region(self.ax_background, bbox=self.ax.bbox)
>
>         # update the data
>         self.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0))
>         self.cos_line.set_ydata((self.x+self.cnt)/50.0)
>         # just draw the animated artist
>         self.ax.draw_artist(self.sin_line)
>         self.ax.draw_artist(self.cos_line)
>         # just redraw the axes rectangle
>         self.blit(self.ax.bbox)
>
>         if self.cnt == 0:
>             self.draw()
>         self.cnt += 1
>
> app = QtGui.QApplication(sys.argv)
> widget = BlitQT()
> widget.show()
>
> sys.exit(app.exec_())
>
>
>
The problem here is probably with the blitting.  You make a copy of the
background before plotting the data.  Before you plot the data, the axes
have no clue what's its limits are supposed to be.  In your example, it
won't know until you do the plotting.  Then when you restore the background,
it is restoring the background that never knew the limits.

I suggest calling ax.set_xlim() and ax.set_ylim() before doing the
copy_from_bbox().

I hope that helps,
Ben Root
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to