我有 2 个颜色条,我希望它们都有不同的pickevents 我该怎么做?我的代码自动取款机是
x_ax.set_picker(5)##colorbar set picker
def on_pick(event):
artist = event.artist
val = event.mouseevent.ydata
xal = event.mouseevent.xdata
if highlight == 1 :
print 'hello'
global highlight
highlight = 0
self.canvas.draw()
if highlight == 0 :
highlight = 2
trans = transforms.blended_transform_factory(self.ax.transAxes,self.ax.transData )
rect = patches.Rectangle((0,1),width=5, height=5, transform=trans, color='yellow',alpha=0.5)
self.ax.add_patch(rect)
self.canvas.draw()
rect.remove()
else:
self.canvas.draw()
trans = transforms.blended_transform_factory(self.ax.transAxes,self.ax.transData )
rect = patches.Rectangle((0,10),width=25, height=25, transform=trans, color='yellow',alpha=0.5)
self.ax.add_patch(rect)
highlight = 1
self.canvas.draw()
rect.remove()
self.canvas = FigureCanvas(self, -1, self.fig)
self.canvas.mpl_connect('pick_event',on_pick)
我尝试添加x2_ax.setpicker(5)
, self.canvas.mpl.connect('pick_event', on_click)
但是当您单击任一颜色栏时,它似乎都同时执行了
我的 on_pick 只是突出显示图表上的一个部分
如何为每个颜色条添加单独的选择事件???