Hello all!
I just recently downloaded Matplotlib and love it so far
A hopefully quick question. In all the demo examples, the navigation bar
has buttons for incremental +/- zoom in the X/Y directions, but no way
to directly choose a rectange within the figure window to zoom to like
in matlab. It gets very tedious the way it is if a lot of zooming and
panning is involved.
I found that I could draw a rectange in the axes and update its
coordinates on an motion_notify_event. The problem is I do not know how
to link the event.get_pointer() coordinates to the coordinates within
the axes. Therefore I cannot set the coordinates of the rectangle
correctly. The following code which is slightly modified from
embed_gtk2.py demonstrates what I am trying to do...
Thanks,
···
--
Srinath
from matplotlib.numerix import arange, sin, cos, pi
import matplotlib
matplotlib.use('GTK')
from matplotlib.backends.backend_gtk import FigureCanvasGTK
from matplotlib.axes import Subplot
from matplotlib.figure import Figure
import gtk
class MyApp:
def __init__(self):
self.win = gtk.Window()
self.win.set_name("Embedding in GTK")
self.win.connect("destroy", gtk.mainquit)
self.win.set_border_width(5)
self.vbox = gtk.VBox(spacing=3)
self.win.add(self.vbox)
self.vbox.show()
self.fig = Figure(figsize=(5,4), dpi=100)
self.ax = Subplot(self.fig, 111)
self.recth = 0.2
self.ylast = 0
x = [0,0.5,0.5,0,0]
y = [0,0,self.recth,self.recth,0]
t = [0,1]
r = [0,1]
self.h = self.ax.plot(x,y,t,r)
self.fig.add_axis(self.ax)
self.canvas = FigureCanvasGTK(self.fig) # a gtk.DrawingArea
self.canvas.show()
self.canvas.connect('motion_notify_event', self.findClick)
self.vbox.pack_start(self.canvas)
self.win.show()
def findClick(self, widget, event):
ynow = event.get_coords()[1]
if ynow < self.ylast:
self.recth += 0.01
elif ynow > self.ylast:
self.recth -= 0.01
self.h[0].set_ydata([0,0,self.recth,self.recth,0])
self.ylast = ynow
self.canvas.draw()
if __name__=='__main__':
app = MyApp()
gtk.mainloop()