* Short Story : I want to create my custom navigation bar with my custom zoom behavior: My first step is zooming by pressing +/- keys to zoom in and zoom out while pointing the mouse to the "zoom's center". I the long run I want a zooming and panning behavior interact smoothly with images (similar to photoshop's): - Zooming with the left button to zoom in the right button to zoom out. - Zooming with the mouse wheel. - Other interactions ...
But I am stuck :-( * Question : My question is how do you "magnify" the image after change the axes ? (with self.axes.set_xlim((x1, x2)) self.axes.set_ylim((y1, y2)) ) * Long story: First, I wanted to understand how the zoom worked. So I traced the zoom functionality from the NavigationToolbar2Wx to the following method: - backend._bases.NavigationToolbar2.drag_pan From what I understand, this is where the magic bar happens? Now I wrote a dirty method ( see OnKeyPress below ) where I drive the zoom by changing the xmin,xmax,ymin,ymax when I press any key instead of the default mouse dragging behavior. When I zoom out: xmin,xmax = Xmin + 50, Xmax - 50 ymin,ymax = Ymin + 50, Ymax – 50 it works find. The image becomes smaller. But, when I zoom in as below xmin,xmax = Xmin - 50, Xmax + 50 ymin,ymax = Ymin - 50, Ymax + 50 the image just get cropped but not magnified. I other words self.axes.set_xlim and self.axes.set_ylim do not make the "data pixels bigger" (as happends in the correct zoom funcionality), they just stay the same size. The image becomes smaller and smaller instead of keeping the same size with les "data pixels into it"… def OnKeyPress(self, event): if not event.inaxes: return x, y = self.axes.transData.inverse_xy_tup( (event.x, event.y)) Xmin,Xmax=self.axes.get_xlim() Ymin,Ymax=self.axes.get_ylim() # Dirty hack to understand how zoom works xmin,xmax = Xmin - 50, Xmax + 50 ymin,ymax = Ymin - 50, Ymax + 50 if self.axes.get_xscale()=='log': alpha=log(Xmax/Xmin)/log(xmax/xmin) x1=pow(Xmin/xmin,alpha)*Xmin x2=pow(Xmax/xmin,alpha)*Xmin else: alpha=(Xmax-Xmin)/(xmax-xmin) x1=alpha*(Xmin-xmin)+Xmin x2=alpha*(Xmax-xmin)+Xmin if self.axes.get_yscale()=='log': alpha=log(Ymax/Ymin)/log(ymax/ymin) y1=pow(Ymin/ymin,alpha)*Ymin y2=pow(Ymax/ymin,alpha)*Ymin else: alpha=(Ymax-Ymin)/(ymax-ymin) y1=alpha*(Ymin-ymin)+Ymin y2=alpha*(Ymax-ymin)+Ymin self.axes.set_xlim((x1, x2)) self.axes.set_ylim((y1, y2)) self.canvas.draw() Any help would be welcomed! Daniel. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel