Hi,
I would like to react on mouse-clicks
by adding lines to a plot
(see the example at the end of this mail).
However, the additional lines, plotted inside
the on_press event handler, are not shown
(only after clicking on the "home" button, or zoom, they
appear). This is with matplotlib 0.80, debian, GTKAgg frontend.
Is there a simple trick to make them visible?
Many thanks in advance,
Arnd
# ---------------------------------
from pylab import *
phi=arange(0.0,2.0*pi+0.05,0.1)
x=cos(phi)
y=sin(phi)
w,h=12,6
fig=figure(figsize=(w, h), dpi=100)
ax1 = fig.add_axes([0.1, 0.55, 0.8, 0.4])
plot(phi,x)
ax2 = fig.add_axes([0.1, 0.1, 0.35*h/w, 0.35])
plot(x,y,linewidth=5)
title ("circular circle?")
xlim(-1.1,1.1 )
ylim(-1.1,1.1 )
xlabel("click in this plot window")
def on_press(event):
"""Draw on button press events."""
print "Event:",event.x,event.y,event.xdata,event.ydata,event.inaxes
if event.inaxes==ax2:
ax1.plot(phi, event.ydata*x, 'r--')
# QUESTION: How can I force to show this line in ax1?
connect('button_press_event', on_press)
show()