mpldatacursor icon indicating copy to clipboard operation
mpldatacursor copied to clipboard

AttributeError: 'NoneType' object has no attribute 'transData'

Open AgilentGCMS opened this issue 1 year ago • 7 comments

I'm trying to use mpldatacursor to label a few points on a plot. Here's an MWE:

from matplotlib import pyplot as plt
import numpy as np
from mpldatacursor import datacursor

xarr = np.array([1.,2.,3.])
yarr = xarr*2
labels = ['Alpha', 'Beta', 'Gamma']

ax = plt.gca()
pts = ax.plot(xarr, yarr, marker='o', ls='None', mfc='r', mec='k', mew=1.0, ms=8.0, label='Example points')
datacursor(pts, hover=True, point_labels=labels, bbox=dict(fc='0.75', alpha=0.75), xytext=(20,25))

When I click on any of the three points plotted, no label appears and I get this error:

Traceback (most recent call last):
  File "/Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 287, in process
    func(*args, **kwargs)
  File "/Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mpldatacursor/datacursor.py", line 704, in _select
    fixed_event = event_axes_data(event, anno.axes)
  File "/Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mpldatacursor/datacursor.py", line 687, in event_axes_data
    x, y = ax.transData.inverted().transform_point(point)
AttributeError: 'NoneType' object has no attribute 'transData'

The above traceback is repeated about a dozen times. I'm using matplotlib 3.5.3 with python 3.9.14. My matplotlib backend is MacOSX.

AgilentGCMS avatar Sep 20 '22 01:09 AgilentGCMS