joferkington / mpldatacursor

Interactive "data cursors" (a.k.a. annotation pop-ups) for matplotlib
MIT License
194 stars 47 forks source link

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

Open AgilentGCMS opened 2 years ago

AgilentGCMS commented 2 years ago

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.

DHWill commented 2 years ago

I am Also getting the same issue,

Python 3.10.2 matplotlib 3.6.0 mpldatacursor 0.7.dev0 numpy 1.23.3

Traceback (most recent call last): File "C:\Users\Will.Parry\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\cbook\__init__.py", line 307, in process func(*args, **kwargs) File "C:\Users\Will.Parry\AppData\Local\Programs\Python\Python310\lib\site-packages\mpldatacursor-0.7.dev0-py3.10.egg\mpldatacursor\datacursor.py", line 710, in _select fixed_event = event_axes_data(event, anno.axes) File "C:\Users\Will.Parry\AppData\Local\Programs\Python\Python310\lib\site-packages\mpldatacursor-0.7.dev0-py3.10.egg\mpldatacursor\datacursor.py", line 693, in event_axes_data x, y = ax.transData.inverted().transform_point(point) AttributeError: 'NoneType' object has no attribute 'transData' Traceback (most recent call last):

sivarticus commented 1 year ago

Same issue for me as well

Python 3.8.10 matplotlib 3.6.2 mpldatacursor 0.7.1 (installed from pip) numpy 1.24.1

MohdFarag commented 1 year ago

Same issue for me

Python 3.10.7 matplotlib 3.6.2 numpy 1.24.1 mpldatacursor 0.7.1 [From pip]

juanjomendezhealios commented 1 year ago

Same issue for me, the code was done previous this issue was opened and it was working fine then. Now, it returns this error.

Python 3.9 matplotlib 3.5.1 mpldatacursor 0.7.1 [from pip]

I'm also using MacOS, but with an Apple Silicon chip.

eyalk11 commented 1 year ago

+1

joellutz commented 11 months ago

Same issue for me as well.

Python 3.10.4 64 Bit matplotlib 3.6.2 mpldatacursor 0.7.1 [from pip] numpy 1.22.3

thanojo commented 8 months ago

Still an issue here as well:

Python 3.11.8 64 Bit matplotlib 3.6.3 [to avoid #116 ] mpldatacursor 0.7.1 [from pip] numpy 1.26.4

clean virtual env on Windows 10

Will update this post if workaround is found

rikaminski commented 3 months ago

Probably the 'ax' is not receiving anything and should receive some object. Try passing the figure first.