Reputation: 4307
Here is what I tried:
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)
And the error
AttributeError: 'AxesSubplot' object has no attribute 'canvas'
Edit: fig is of type AxesSubplot, and is instantiated like this
fig = plt.subplot2grid((i, i), (j, 0), rowspan=1, colspan=i)
What is the easiest way to add tooltips on my scatterplot? Please note that I want to keep my current framework, with calling fig.scatter, as these scatters are overlaid on an existing figure.
Upvotes: 1
Views: 2686
Reputation: 97261
subplot2grid()
returns an Axes
object, use it's figure
attribute to get the figure object:
import pylab as pl
axes = pl.subplot2grid((2, 2), (0, 0), rowspan=1, colspan=1)
axes.figure.canvas.mpl_connect('pick_event', onpick3)
Upvotes: 2