You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The contour label (clabel) manual mode fails place any labels. When I click the plot I get an error:
'QuadContourSet' object has no attribute 'ax'
and no labels are added.
I put the Contour Label Demo as an example with clabel option manual=True, but this has happened with different scripts.
Code for reproduction
importnumpyasnpimportmatplotlib.tickerastickerimportmatplotlib.pyplotaspltdelta=0.025x=np.arange(-3.0, 3.0, delta)
y=np.arange(-2.0, 2.0, delta)
X, Y=np.meshgrid(x, y)
Z1=np.exp(-X**2-Y**2)
Z2=np.exp(-(X-1)**2- (Y-1)**2)
Z= (Z1-Z2) *2# This custom formatter removes trailing zeros, e.g. "1.0" becomes "1", and# then adds a percent sign.deffmt(x):
s=f"{x:.1f}"ifs.endswith("0"):
s=f"{x:.0f}"returnrf"{s} \%"ifplt.rcParams["text.usetex"] elsef"{s} %"# Basic contour plotfig, ax=plt.subplots()
CS=ax.contour(X, Y, Z)
ax.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10, manual=True)
plt.show()
Actual outcome
I get the following error:
Traceback (most recent call last):
File "/Users/azahel/anaconda3/lib/python3.9/site-packages/matplotlib/cbook/init.py", line 287, in process
func(*args, **kwargs)
File "/Users/azahel/anaconda3/lib/python3.9/site-packages/matplotlib/contour.py", line 70, in _contour_labeler_event_handler
if event.inaxes == cs.ax:
AttributeError: 'QuadContourSet' object has no attribute 'ax'
Expected outcome
Additional information
I recently upgraded matplotlib to 3.5.1, I'm not sure if this was a problem with previous versions.
Checking the file contour.py it is clear that ContourSet, and by extension QuadContourSet, do not have the attribute "ax" but rather "axes".
Changing line 70 from contour.py
" if event.inaxes == cs.ax:"
to
" if event.inaxes == cs.axes:"
resolves the issue.
Seeing in the documentation that Contour set is described to have the attribute "ax", perhaps the real fix would be to change ContourSet class.
Operating system
OS/X
Matplotlib Version
3.5.1
Matplotlib Backend
MacOSX
Python version
3.9.12
Jupyter version
No response
Installation
conda
The text was updated successfully, but these errors were encountered:
I think this is a duplicate of #22760 - events were broken on MacOS, but are working on the dev build (upcoming 3.6). Please use Qt5Agg, the dev version of Matplotlib or roll back to 3.4.x....
I have tried it now with Qt5Agg and the issue persists, unless I do the fix I proposed. I'm also aware that the event handlers with MacOS are broken, but I think this is a separate issue.
Bug summary
The contour label (clabel) manual mode fails place any labels. When I click the plot I get an error:
'QuadContourSet' object has no attribute 'ax'
and no labels are added.
I put the Contour Label Demo as an example with clabel option manual=True, but this has happened with different scripts.
Code for reproduction
Actual outcome
I get the following error:
Traceback (most recent call last):
File "/Users/azahel/anaconda3/lib/python3.9/site-packages/matplotlib/cbook/init.py", line 287, in process
func(*args, **kwargs)
File "/Users/azahel/anaconda3/lib/python3.9/site-packages/matplotlib/contour.py", line 70, in _contour_labeler_event_handler
if event.inaxes == cs.ax:
AttributeError: 'QuadContourSet' object has no attribute 'ax'
Expected outcome
Additional information
I recently upgraded matplotlib to 3.5.1, I'm not sure if this was a problem with previous versions.
Checking the file contour.py it is clear that ContourSet, and by extension QuadContourSet, do not have the attribute "ax" but rather "axes".
Changing line 70 from contour.py
" if event.inaxes == cs.ax:"
to
" if event.inaxes == cs.axes:"
resolves the issue.
Seeing in the documentation that Contour set is described to have the attribute "ax", perhaps the real fix would be to change ContourSet class.
Operating system
OS/X
Matplotlib Version
3.5.1
Matplotlib Backend
MacOSX
Python version
3.9.12
Jupyter version
No response
Installation
conda
The text was updated successfully, but these errors were encountered: