Skip to content

[Bug]: Type hints for where argument in ax.fill_between does not allow np.ndarrays #31890

@acampove

Description

@acampove

Bug summary

Pyright shows errors when passing numpy arrays to fill_between

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x = np.array([0, 1, 2, 3, 4])
y = np.array([1.0, 2.0, 3.0, 2.0, 1.0])
err = np.array([0.1, 0.2, 0.1, 0.2, 0.1])

fig, ax = plt.subplots()

ax.fill_between(
    x,
    y1=(y - err),
    y2=(y + err),
)

Actual outcome

WARNING: there is a new pyright version available (v1.1.409 -> v1.1.410).
Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest`

/home/acampove/Tests/matplotlib/test.py
  /home/acampove/Tests/matplotlib/test.py:12:8 - error: Argument of type "NDArray[Any]" cannot be assigned to parameter "y1" of type "Scalar" in function "fill_between"
    Type "NDArray[Any]" is not assignable to type "Scalar"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "str"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "int"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "float"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "bool"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "Period"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "Timestamp"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "Timedelta"
    ... (reportArgumentType)
  /home/acampove/Tests/matplotlib/test.py:13:8 - error: Argument of type "NDArray[Any]" cannot be assigned to parameter "y2" of type "Scalar" in function "fill_between"
    Type "NDArray[Any]" is not assignable to type "Scalar"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "str"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "int"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "float"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "bool"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "Period"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "Timestamp"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "Timedelta"
    ... (reportArgumentType)
2 errors, 0 warnings, 0 informations

Expected outcome

No errors

Additional information

pyright 1.1.409

Name: numpy
Version: 2.3.5

Operating system

No response

Matplotlib Version

3.10.8

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions