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]: typing.get_type_hints fails for multiple pyplot plotting functions #28977

Open
@YoraiLevi

Description

@YoraiLevi

Bug summary

typing.get_type_hints throws errorname 'ArrayLike' is not defined for pyplot functions such as plot,scatter,imshow etc.

Code for reproduction

%pipinstall-Umatplotlib# colabimporttypingimportmatplotlib.pyplotimportmatplotlib.typing# sanity check, typing existprint(matplotlib.pyplot.imshow.__annotations__)typing.get_type_hints(matplotlib.pyplot.imshow)

Actual outcome

{'X': 'ArrayLike | PIL.Image.Image', 'cmap': 'str | Colormap | None', 'norm': 'str | Normalize | None', 'aspect': "Literal['equal', 'auto'] | float | None", 'interpolation': 'str | None', 'alpha': 'float | ArrayLike | None', 'vmin': 'float | None', 'vmax': 'float | None', 'origin': "Literal['upper', 'lower'] | None", 'extent': 'tuple[float, float, float, float] | None', 'interpolation_stage': "Literal['data', 'rgba'] | None", 'filternorm': 'bool', 'filterrad': 'float', 'resample': 'bool | None', 'url': 'str | None', 'return': 'AxesImage'}---------------------------------------------------------------------------NameError                                 Traceback (most recent call last)[<ipython-input-6-616de5754b17>](https://localhost:8080/#) in <cell line: 7>()      5       6 print(matplotlib.pyplot.imshow.__annotations__)----> 7 typing.get_type_hints(matplotlib.pyplot.imshow)3 frames/usr/local/lib/python3.10/dist-packages/matplotlib/pyplot.py in <module>NameError: name 'ArrayLike' is not defined

Expected outcome

a dictionary with correctly populated classes, no error

fromnumpy.typingimportArrayLikedefimshow(X:ArrayLike):passtyping.get_type_hints(imshow)
{'X': typing.Union[numpy._typing._array_like._SupportsArray[numpy.dtype[typing.Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[typing.Any]]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes]]}

Additional information

when using colab matplotlib needs to be upgraded to include typing annotations

Operating system

Ubuntu

Matplotlib Version

3.9.2

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10.12

Jupyter version

6.5.5

Installation

pip

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