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]: matplotlib.units.ConversionInterface not being called for a registered type #24269

Open
@l-johnston

Description

@l-johnston

Bug summary

The documentation for matplotlib.units states:

The classes here provide support for using custom classes with Matplotlib, e.g., those that do not expose the array interface but know how to convert themselves to arrays. It also supports classes with units and units conversion.

without defining the meaning of, and implication of, "array interface". Ultimately, and fundamentally the problem here is that plotting functions like matplotlib.pyplot.plot() cast the x and y data to numpy.ndarray() immediately without consulting the matplotlib.units.registry first and this means that custom classes that are List-like with values that are Number-like are immediately converted to numpy.ndarray and the conversion interface is never called.

Code for reproduction

importmatplotlib.unitsasmpl_unitsclassQuantity(float):"""simple quantity"""classQlist(list):"""a list of Quantity objects"""classQlistConverter(mpl_units.ConversionInterface):@staticmethoddefconvert(obj,unit,axis):print("QlistConverter.convert()")returnobj@staticmethoddefaxisinfo(unit,axis):print("QlistConverter.axisinfo()")returnmpl_units.AxisInfo()@staticmethoddefdefault_units(x,axis):print("QlistConverter.default_units()")returnximportmatplotlib.pyplotaspltx=Qlist([Quantity(1),Quantity(2),Quantity(3)])y=Qlist([Quantity(4),Quantity(5),Quantity(6)])mpl_units.registry[Qlist]=QlistConverter()plt.plot(x,y)plt.gca().xaxis.converterisNone

Actual outcome

True

Expected outcome

Expected the QlistConverter to be called

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

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