|
From: John H. <jdh...@ac...> - 2004-04-16 22:21:49
|
>>>>> "Srinath" == Srinath Avadhanula <sr...@fa...> writes:
Srinath> Hello all! I just recently downloaded Matplotlib and
Srinath> love it so far :)
Thanks!
Srinath> A hopefully quick question. In all the demo examples, the
Srinath> navigation bar has buttons for incremental +/- zoom in
Srinath> the X/Y directions, but no way to directly choose a
Srinath> rectange within the figure window to zoom to like in
Srinath> matlab. It gets very tedious the way it is if a lot of
Srinath> zooming and panning is involved.
Srinath> I found that I could draw a rectange in the axes and
Srinath> update its coordinates on an motion_notify_event. The
Srinath> problem is I do not know how to link the
Srinath> event.get_pointer() coordinates to the coordinates within
Srinath> the axes. Therefore I cannot set the coordinates of the
Srinath> rectangle correctly. The following code which is slightly
Srinath> modified from embed_gtk2.py demonstrates what I am trying
Srinath> 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()
|