Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: clabel manual argument does not accept units #27525

Open
@QuLogic

Description

@QuLogic

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

589d3fb

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp