【发布时间】:2014-01-11 19:18:34
【问题描述】:
Matplotlib Widget Buttons 事件和 fig.canvas.mpl_connect('button_press_event') 都会在鼠标点击按钮时触发。
我的问题是:
1) 如何使 fig.canvas.mpl_connect('button_press_event') 事件具有更高的优先级? 和 2) 如何在 fig.canvas.mpl_connect('button_press_event') 事件中判断按钮是否被点击。
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
fig = plt.figure()
# plotting
X=[1,2,3]
Y=[10,20,30]
ax = fig.add_subplot(1, 1, 1)
ax.plot(X,Y,'bo-')
ax.grid()
ax.legend()
X1=[]
Y1=[]
def on_press(event):
print "canvas clicked"
print "how can I tell whether the button is clicked?"
print event
def on_button_clicked(event):
print "button clicked"
print event
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])
bnext = Button(axnext, 'Next')
bnext.on_clicked(on_button_clicked)
fig.canvas.mpl_connect('button_press_event', on_press)
plt.show()
【问题讨论】:
标签: button matplotlib widget