这是我尝试过的:
def onpick3(event):
ind = event.ind
print 'onpick3 scatter:'
fig.scatter(t, p, color='b', zorder=10, label='label', picker=True)
fig.legend(loc=fills_legend_pos[index])
fig.canvas.mpl_connect('pick_event', onpick3)
还有错误
AttributeError: 'AxesSubplot' object has no attribute 'canvas'
编辑:fig 是 AxesSubplot 类型,并像这样实例化
fig = plt.subplot2grid((i, i), (j, 0), rowspan=1, colspan=i)
在散点图上添加工具提示的最简单方法是什么?请注意,我想保留当前的框架,并调用Fig.scatter,因为这些散点图覆盖在现有的图形上。
最佳答案
subplot2grid()
返回一个Axes
对象,使用它的figure
属性来获取figure对象:
import pylab as pl
axes = pl.subplot2grid((2, 2), (0, 0), rowspan=1, colspan=1)
axes.figure.canvas.mpl_connect('pick_event', onpick3)
关于python - Matplotlib - 鼠标悬停时的工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24274532/