SourceForge logo
SourceForge logo
Menu

matplotlib-devel

From: Daniel K. <kor...@re...> - 2006年09月24日 06:55:34
* 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.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /