Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Bug summary
As found in#27490, whilecontour
does appear to allow units, if you pass manual label locations to themanual
argument of `clabel, it will fail.
Code for reproduction
importdatetimeimportnumpyasnpimportmatplotlib.pyplotasplt# Sample data for contour plotdates= [datetime.datetime(2023,10,1)+datetime.timedelta(days=i)foriinrange(10)]x_start,x_end,x_step=-10.0,5.0,0.5y_start,y_end,y_step=0,10,1x=np.arange(x_start,x_end,x_step)y=np.arange(y_start,y_end,y_step)# In this case, Y axis has datesX,Y=np.meshgrid(x,dates)rows=len(X)cols=len(X[0])z1D=np.arange(rows*cols)Z=z1D.reshape((rows,cols))fig,ax=plt.subplots()CS=ax.contour(X,Y,Z)ax.clabel(CS,CS.levels,inline=True,fmt=dict(zip(CS.levels,dates)),manual=[(x,y)forx,yinzip(x,dates)])
Actual outcome
Traceback (mostrecentcalllast):File"/home/elliott/code/matplotlib/clabel.py",line27,in<module>ax.clabel(CS,CS.levels,inline=True,fmt=dict(zip(CS.levels,dates)),File"/home/elliott/code/matplotlib/lib/matplotlib/axes/_axes.py",line6581,inclabelreturnCS.clabel(levels,**kwargs)File"/home/elliott/code/matplotlib/lib/matplotlib/contour.py",line195,inclabelself.add_label_near(x,y,inline,inline_spacing)File"/home/elliott/code/matplotlib/lib/matplotlib/contour.py",line553,inadd_label_nearx,y=transform.transform((x,y))File"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py",line1508,intransformres=self.transform_affine(self.transform_non_affine(values))File"/home/elliott/code/matplotlib/lib/matplotlib/_api/deprecation.py",line297,inwrapperreturnfunc(*args,**kwargs)File"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py",line2422,intransform_affinereturnself.get_affine().transform(values)File"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py",line1797,intransformreturnself.transform_affine(values)File"/home/elliott/code/matplotlib/lib/matplotlib/_api/deprecation.py",line297,inwrapperreturnfunc(*args,**kwargs)File"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py",line1868,intransform_affinereturnaffine_transform(values,mtx)TypeError:Cannotcastarraydatafromdtype('O')todtype('float64')accordingtotherule'safe'
Expected outcome
Labels are added at spots corresponding to those given inmanual
.
Additional information
No response
Operating system
No response
Matplotlib Version
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
git checkout