mpldatacursor icon indicating copy to clipboard operation
mpldatacursor copied to clipboard

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

Open AgilentGCMS opened this issue 2 years ago • 8 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

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):

DHWill avatar Sep 26 '22 11:09 DHWill

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

sivarticus avatar Jan 07 '23 16:01 sivarticus

Same issue for me

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

MohdFarag avatar Jan 22 '23 22:01 MohdFarag

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.

juanjomendezhealios avatar Mar 28 '23 13:03 juanjomendezhealios

+1

eyalk11 avatar Jun 09 '23 21:06 eyalk11

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

joellutz avatar Nov 20 '23 07:11 joellutz

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

thanojo avatar Feb 27 '24 15:02 thanojo