Hello all! I just recently downloaded Matplotlib and
> love it so far
Thanks!
> 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...
Yes, this would be a very nive feature. When you implement it, please
send it back to the list. Here is an example that shows you how to
connect to the events and more importantly for you, convert to user
coords
"""
An example of how to interact with the plotting canvas by connecting
to move and click events
"""
from matplotlib.matlab import *
t = arange(0.0, 1.0, 0.01)
s = sin(2*pi*t)
ax = subplot(111)
ax.plot(t,s)
canvas = get_current_fig_manager().canvas
def on_move(widget, event):
# get the x and y coords, flip y from top to bottom
height = canvas.figure.bbox.y.interval()
x, y = event.x, height-event.y
if ax.in_axes(x, y):
# transData transforms data coords to display coords. Use the
# inverse method to transform back
t = ax.xaxis.transData.inverse_positions(x)
val = ax.yaxis.transData.inverse_positions(y)
print t, val
def on_click(widget, event):
# get the x and y coords, flip y from top to bottom
height = canvas.figure.bbox.y.interval()
x, y = event.x, height-event.y
if event.button==1:
if ax.in_axes(x, y):
# transData transforms data coords to display coords. Use the
# inverse method to transform back
t = ax.xaxis.transData.inverse_positions(x)
val = ax.yaxis.transData.inverse_positions(y)
print t, val
#canvas.connect('motion_notify_event', on_move)
canvas.connect('button_press_event', on_click)
show()