2014-06-17 154 views
1

這裏是我的嘗試:Matplotlib - 鼠標提示懸停

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' 

編輯:無花果類型AxesSubplot的,並且被實例化這樣

fig = plt.subplot2grid((i, i), (j, 0), rowspan=1, colspan=i) 

在我的散點圖上添加工具提示最簡單的方法是什麼?請注意,我想保留當前的框架,並調用fig.scatter,因爲這些散點圖覆蓋在現有的圖形上。

+0

如何定義'fig'?儘管稱它爲'fig',它似乎是一個沒有'canvas'屬性的對象! – bernie

回答

1

subplot2grid()返回Axes對象,使用它的figure屬性來獲得人物對象:

import pylab as pl 
axes = pl.subplot2grid((2, 2), (0, 0), rowspan=1, colspan=1) 
axes.figure.canvas.mpl_connect('pick_event', onpick3) 
+0

現在我得到 /usr/lib64/python2.7/site-packages/numexpr/necompiler.py:746:DeprecationWarning:op_axes'爲NULL時使用'oa_ndim == 0'已被棄用。使用'oa_ndim == -1'或MultiNew迭代器來實現NumPy <1.8兼容性 並且不顯示工具提示。 –