10000 [Bug]: typehint missing for matplotlib Axes · Issue #28210 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: typehint missing for matplotlib Axes #28210
Closed as not planned
Closed as not planned
@dlefcoe

Description

@dlefcoe

Bug summary

plt.subplots in matplotlib 3.8.0 returns tuple[Figure, Any], so Pylance doesn't know the type of ax

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.axes import Axes        # added this

fig, ax = plt.subplots()
ax: Axes                                # added this

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
colours = ['red', 'blue', 'red', 'orange']

ax.bar(fruits, counts, label=colours, color=colours)

ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')

plt.show()

Actual outcome

The intelisense does not work for ax so it has to be explicitly typehinted.

Expected outcome

The import of Axes and the typehint of ax should not be required.

Additional information

please see this stackoverflow link: https://stackoverflow.com/questions/77368904/methods-and-attributes-do-not-show-when-dot-is-pressed-intellisense

Operating system

windows 11

Matplotlib Version

3.8.0

Matplotlib Backend

TkAgg

Python version

3.12

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0