From 8a1f201c898aa7a509ba1d56670976ba51b0155b Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 9 Apr 2026 22:35:13 +0200 Subject: [PATCH 1/2] TYP: Add type information to the data parameter of plot functions Closes #31480. We type all as `Mapping[str, Any]`. Some uses have actually a broad range of supported types because they map quite a number of parameters. Even for the ones which we know all parameters supported by `data` are ArrayLike, typing as `Mapping[str, ArrayLike]` may be too risky, as the user may have more keys in the data structure, which we don't use, but their values would be type checked and could be anything. --- lib/matplotlib/axes/_axes.pyi | 81 ++++++++++++------------- lib/matplotlib/pyplot.py | 107 +++++++++++++++++----------------- lib/matplotlib/typing.py | 5 +- 3 files changed, 99 insertions(+), 94 deletions(-) diff --git a/lib/matplotlib/axes/_axes.pyi b/lib/matplotlib/axes/_axes.pyi index 09587ab753a3..3c222bd6bc1d 100644 --- a/lib/matplotlib/axes/_axes.pyi +++ b/lib/matplotlib/axes/_axes.pyi @@ -37,7 +37,8 @@ from collections.abc import Callable, Iterable, Sequence from typing import Any, Literal, overload import numpy as np from numpy.typing import ArrayLike -from matplotlib.typing import ColorType, MarkerType, LegendLocType, LineStyleType +from matplotlib.typing import ( + ColorType, DataParamType, MarkerType, LegendLocType, LineStyleType) import pandas as pd @@ -172,7 +173,7 @@ class Axes(_AxesBase): linestyles: LineStyleType = ..., *, label: str = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> LineCollection: ... def vlines( @@ -184,7 +185,7 @@ class Axes(_AxesBase): linestyles: LineStyleType = ..., *, label: str = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> LineCollection: ... def eventplot( @@ -198,7 +199,7 @@ class Axes(_AxesBase): colors: ColorType | Sequence[ColorType] | None = ..., alpha: float | Sequence[float] | None = ..., linestyles: LineStyleType | Sequence[LineStyleType] = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> EventCollection: ... def plot( @@ -206,14 +207,14 @@ class Axes(_AxesBase): *args: float | ArrayLike | str, scalex: bool = ..., scaley: bool = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> list[Line2D]: ... def loglog(self, *args, **kwargs) -> list[Line2D]: ... def semilogx(self, *args, **kwargs) -> list[Line2D]: ... def semilogy(self, *args, **kwargs) -> list[Line2D]: ... def acorr( - self, x: ArrayLike, *, data=..., **kwargs + self, x: ArrayLike, *, data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: ... def xcorr( self, @@ -224,7 +225,7 @@ class Axes(_AxesBase): detrend: Callable[[ArrayLike], ArrayLike] = ..., usevlines: bool = ..., maxlags: int = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: ... def step( @@ -233,7 +234,7 @@ class Axes(_AxesBase): y: ArrayLike, *args, where: Literal["pre", "post", "mid"] = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> list[Line2D]: ... def bar( @@ -244,7 +245,7 @@ class Axes(_AxesBase): bottom: float | ArrayLike | None = ..., *, align: Literal["center", "edge"] = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> BarContainer: ... def barh( @@ -255,7 +256,7 @@ class Axes(_AxesBase): left: float | ArrayLike | None = ..., *, align: Literal["center", "edge"] = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> BarContainer: ... def bar_label( @@ -274,7 +275,7 @@ class Axes(_AxesBase): yrange: tuple[float, float], align: Literal["bottom", "center", "top"] = ..., *, - data=..., + data: DataParamType = ..., **kwargs ) -> PolyCollection: ... def grouped_bar( @@ -299,7 +300,7 @@ class Axes(_AxesBase): bottom: float = ..., label: str | None = ..., orientation: Literal["vertical", "horizontal"] = ..., - data=..., + data: DataParamType = ..., ) -> StemContainer: ... # TODO: data kwarg preprocessor? @@ -324,7 +325,7 @@ class Axes(_AxesBase): rotatelabels: bool = ..., normalize: bool = ..., hatch: str | Sequence[str] | None = ..., - data=..., + data: DataParamType = ..., ) -> PieContainer: ... def pie_label( self, @@ -356,7 +357,7 @@ class Axes(_AxesBase): xuplims: bool | ArrayLike = ..., errorevery: int | tuple[int, int] = ..., capthick: float | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> ErrorbarContainer: ... def boxplot( @@ -391,7 +392,7 @@ class Axes(_AxesBase): zorder: float | None = ..., capwidths: float | ArrayLike | None = ..., label: Sequence[str] | None = ..., - data=..., + data: DataParamType = ..., ) -> dict[str, Any]: ... def bxp( self, @@ -436,7 +437,7 @@ class Axes(_AxesBase): edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = ..., colorizer: Colorizer | None = ..., plotnonfinite: bool = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> PathCollection: ... def hexbin( @@ -461,7 +462,7 @@ class Axes(_AxesBase): mincnt: int | None = ..., marginals: bool = ..., colorizer: Colorizer | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> PolyCollection: ... def arrow( @@ -470,9 +471,9 @@ class Axes(_AxesBase): def quiverkey( self, Q: Quiver, X: float, Y: float, U: float, label: str, **kwargs ) -> QuiverKey: ... - def quiver(self, *args, data=..., **kwargs) -> Quiver: ... - def barbs(self, *args, data=..., **kwargs) -> Barbs: ... - def fill(self, *args, data=..., **kwargs) -> list[Polygon]: ... + def quiver(self, *args, data: DataParamType = ..., **kwargs) -> Quiver: ... + def barbs(self, *args, data: DataParamType = ..., **kwargs) -> Barbs: ... + def fill(self, *args, data: DataParamType = ..., **kwargs) -> list[Polygon]: ... def fill_between( self, x: ArrayLike, @@ -482,7 +483,7 @@ class Axes(_AxesBase): interpolate: bool = ..., step: Literal["pre", "post", "mid"] | None = ..., *, - data=..., + data: DataParamType = ..., **kwargs ) -> FillBetweenPolyCollection: ... def fill_betweenx( @@ -494,7 +495,7 @@ class Axes(_AxesBase): step: Literal["pre", "post", "mid"] | None = ..., interpolate: bool = ..., *, - data=..., + data: DataParamType = ..., **kwargs ) -> FillBetweenPolyCollection: ... def imshow( @@ -516,7 +517,7 @@ class Axes(_AxesBase): filterrad: float = ..., resample: bool | None = ..., url: str | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> AxesImage: ... def pcolor( @@ -529,7 +530,7 @@ class Axes(_AxesBase): vmin: float | None = ..., vmax: float | None = ..., colorizer: Colorizer | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> Collection: ... def pcolormesh( @@ -543,7 +544,7 @@ class Axes(_AxesBase): colorizer: Colorizer | None = ..., shading: Literal["flat", "nearest", "gouraud", "auto"] | None = ..., antialiased: bool = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> QuadMesh: ... def pcolorfast( @@ -555,11 +556,11 @@ class Axes(_AxesBase): vmin: float | None = ..., vmax: float | None = ..., colorizer: Colorizer | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> AxesImage | PcolorImage | QuadMesh: ... - def contour(self, *args, data=..., **kwargs) -> QuadContourSet: ... - def contourf(self, *args, data=..., **kwargs) -> QuadContourSet: ... + def contour(self, *args, data: DataParamType = ..., **kwargs) -> QuadContourSet: ... + def contourf(self, *args, data: DataParamType = ..., **kwargs) -> QuadContourSet: ... def clabel( self, CS: ContourSet, levels: ArrayLike | None = ..., **kwargs ) -> list[Text]: ... @@ -581,7 +582,7 @@ class Axes(_AxesBase): color: ColorType | Sequence[ColorType] | None = ..., label: str | Sequence[str] | None = ..., stacked: bool = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[ np.ndarray | list[np.ndarray], @@ -596,7 +597,7 @@ class Axes(_AxesBase): orientation: Literal["vertical", "horizontal"] = ..., baseline: float | ArrayLike | None = ..., fill: bool = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> StepPatch: ... def hist2d( @@ -614,7 +615,7 @@ class Axes(_AxesBase): weights: ArrayLike | None = ..., cmin: float | None = ..., cmax: float | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray, np.ndarray, QuadMesh]: ... def ecdf( @@ -625,7 +626,7 @@ class Axes(_AxesBase): complementary: bool=..., orientation: Literal["vertical", "horizontal"]=..., compress: bool=..., - data=..., + data: DataParamType = ..., **kwargs ) -> Line2D: ... def psd( @@ -644,7 +645,7 @@ class Axes(_AxesBase): sides: Literal["default", "onesided", "twosided"] | None = ..., scale_by_freq: bool | None = ..., return_line: bool | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: ... def csd( @@ -664,7 +665,7 @@ class Axes(_AxesBase): sides: Literal["default", "onesided", "twosided"] | None = ..., scale_by_freq: bool | None = ..., return_line: bool | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: ... def magnitude_spectrum( @@ -677,7 +678,7 @@ class Axes(_AxesBase): pad_to: int | None = ..., sides: Literal["default", "onesided", "twosided"] | None = ..., scale: Literal["default", "linear", "dB"] | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray, Line2D]: ... def angle_spectrum( @@ -689,7 +690,7 @@ class Axes(_AxesBase): window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ..., pad_to: int | None = ..., sides: Literal["default", "onesided", "twosided"] | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray, Line2D]: ... def phase_spectrum( @@ -701,7 +702,7 @@ class Axes(_AxesBase): window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ..., pad_to: int | None = ..., sides: Literal["default", "onesided", "twosided"] | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray, Line2D]: ... def cohere( @@ -719,7 +720,7 @@ class Axes(_AxesBase): pad_to: int | None = ..., sides: Literal["default", "onesided", "twosided"] = ..., scale_by_freq: bool | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray]: ... def specgram( @@ -743,7 +744,7 @@ class Axes(_AxesBase): scale: Literal["default", "linear", "dB"] | None = ..., vmin: float | None = ..., vmax: float | None = ..., - data=..., + data: DataParamType = ..., **kwargs ) -> tuple[np.ndarray, np.ndarray, np.ndarray, AxesImage]: ... def spy( @@ -778,7 +779,7 @@ class Axes(_AxesBase): side: Literal["both", "low", "high"] = ..., facecolor: Sequence[ColorType] | ColorType | None = ..., linecolor: Sequence[ColorType] | ColorType | None = ..., - data=..., + data: DataParamType = ..., ) -> dict[str, Collection]: ... def violin( self, diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index ed7821ca1b27..777bc4877aa9 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -140,6 +140,7 @@ CloseEventType, ColorType, CoordsType, + DataParamType, DrawEventType, HashableList, KeyEventType, @@ -2999,7 +3000,7 @@ def waitforbuttonpress(timeout: float = -1) -> None | bool: # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_copy_docstring_and_deprecators(Axes.acorr) def acorr( - x: ArrayLike, *, data=None, **kwargs + x: ArrayLike, *, data: DataParamType = None, **kwargs ) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: return gca().acorr(x, **({"data": data} if data is not None else {}), **kwargs) @@ -3014,7 +3015,7 @@ def angle_spectrum( pad_to: int | None = None, sides: Literal["default", "onesided", "twosided"] | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray, Line2D]: return gca().angle_spectrum( @@ -3130,7 +3131,7 @@ def bar( bottom: float | ArrayLike | None = None, *, align: Literal["center", "edge"] = "center", - data=None, + data: DataParamType = None, **kwargs, ) -> BarContainer: return gca().bar( @@ -3146,7 +3147,7 @@ def bar( # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_copy_docstring_and_deprecators(Axes.barbs) -def barbs(*args, data=None, **kwargs) -> Barbs: +def barbs(*args, data: DataParamType = None, **kwargs) -> Barbs: return gca().barbs(*args, **({"data": data} if data is not None else {}), **kwargs) @@ -3159,7 +3160,7 @@ def barh( left: float | ArrayLike | None = None, *, align: Literal["center", "edge"] = "center", - data=None, + data: DataParamType = None, **kwargs, ) -> BarContainer: return gca().barh( @@ -3227,7 +3228,7 @@ def boxplot( capwidths: float | ArrayLike | None = None, label: Sequence[str] | None = None, *, - data=None, + data: DataParamType = None, ) -> dict[str, Any]: return gca().boxplot( x, @@ -3270,7 +3271,7 @@ def broken_barh( yrange: tuple[float, float], align: Literal["bottom", "center", "top"] = "bottom", *, - data=None, + data: DataParamType = None, **kwargs, ) -> PolyCollection: return gca().broken_barh( @@ -3296,16 +3297,15 @@ def cohere( NFFT: int = 256, Fs: float = 2, Fc: int = 0, - detrend: ( - Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] - ) = mlab.detrend_none, + detrend: Literal["none", "mean", "linear"] + | Callable[[ArrayLike], ArrayLike] = mlab.detrend_none, window: Callable[[ArrayLike], ArrayLike] | ArrayLike = mlab.window_hanning, noverlap: int = 0, pad_to: int | None = None, sides: Literal["default", "onesided", "twosided"] = "default", scale_by_freq: bool | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray]: return gca().cohere( @@ -3327,7 +3327,7 @@ def cohere( # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_copy_docstring_and_deprecators(Axes.contour) -def contour(*args, data=None, **kwargs) -> QuadContourSet: +def contour(*args, data: DataParamType = None, **kwargs) -> QuadContourSet: __ret = gca().contour( *args, **({"data": data} if data is not None else {}), **kwargs ) @@ -3338,7 +3338,7 @@ def contour(*args, data=None, **kwargs) -> QuadContourSet: # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_copy_docstring_and_deprecators(Axes.contourf) -def contourf(*args, data=None, **kwargs) -> QuadContourSet: +def contourf(*args, data: DataParamType = None, **kwargs) -> QuadContourSet: __ret = gca().contourf( *args, **({"data": data} if data is not None else {}), **kwargs ) @@ -3355,9 +3355,9 @@ def csd( NFFT: int | None = None, Fs: float | None = None, Fc: int | None = None, - detrend: ( - Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] | None - ) = None, + detrend: Literal["none", "mean", "linear"] + | Callable[[ArrayLike], ArrayLike] + | None = None, window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = None, noverlap: int | None = None, pad_to: int | None = None, @@ -3365,7 +3365,7 @@ def csd( scale_by_freq: bool | None = None, return_line: bool | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: return gca().csd( @@ -3395,7 +3395,7 @@ def ecdf( complementary: bool = False, orientation: Literal["vertical", "horizontal"] = "vertical", compress: bool = False, - data=None, + data: DataParamType = None, **kwargs, ) -> Line2D: return gca().ecdf( @@ -3429,7 +3429,7 @@ def errorbar( capthick: float | None = None, elinestyle: LineStyleType | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> ErrorbarContainer: return gca().errorbar( @@ -3466,7 +3466,7 @@ def eventplot( alpha: float | Sequence[float] | None = None, linestyles: LineStyleType | Sequence[LineStyleType] = "solid", *, - data=None, + data: DataParamType = None, **kwargs, ) -> EventCollection: return gca().eventplot( @@ -3485,7 +3485,7 @@ def eventplot( # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_copy_docstring_and_deprecators(Axes.fill) -def fill(*args, data=None, **kwargs) -> list[Polygon]: +def fill(*args, data: DataParamType = None, **kwargs) -> list[Polygon]: return gca().fill(*args, **({"data": data} if data is not None else {}), **kwargs) @@ -3499,7 +3499,7 @@ def fill_between( interpolate: bool = False, step: Literal["pre", "post", "mid"] | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> FillBetweenPolyCollection: return gca().fill_between( @@ -3524,7 +3524,7 @@ def fill_betweenx( step: Literal["pre", "post", "mid"] | None = None, interpolate: bool = False, *, - data=None, + data: DataParamType = None, **kwargs, ) -> FillBetweenPolyCollection: return gca().fill_betweenx( @@ -3600,7 +3600,7 @@ def hexbin( marginals: bool = False, colorizer: Colorizer | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> PolyCollection: __ret = gca().hexbin( @@ -3649,7 +3649,7 @@ def hist( label: str | Sequence[str] | None = None, stacked: bool = False, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[ np.ndarray | list[np.ndarray], @@ -3686,7 +3686,7 @@ def stairs( orientation: Literal["vertical", "horizontal"] = "vertical", baseline: float | ArrayLike | None = 0, fill: bool = False, - data=None, + data: DataParamType = None, **kwargs, ) -> StepPatch: return gca().stairs( @@ -3712,7 +3712,7 @@ def hist2d( cmin: float | None = None, cmax: float | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray, np.ndarray, QuadMesh]: __ret = gca().hist2d( @@ -3741,7 +3741,7 @@ def hlines( linestyles: LineStyleType = "solid", label: str = "", *, - data=None, + data: DataParamType = None, **kwargs, ) -> LineCollection: return gca().hlines( @@ -3776,7 +3776,7 @@ def imshow( filterrad: float = 4.0, resample: bool | None = None, url: str | None = None, - data=None, + data: DataParamType = None, **kwargs, ) -> AxesImage: __ret = gca().imshow( @@ -3834,7 +3834,7 @@ def magnitude_spectrum( sides: Literal["default", "onesided", "twosided"] | None = None, scale: Literal["default", "linear", "dB"] | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray, Line2D]: return gca().magnitude_spectrum( @@ -3884,7 +3884,7 @@ def pcolor( vmin: float | None = None, vmax: float | None = None, colorizer: Colorizer | None = None, - data=None, + data: DataParamType = None, **kwargs, ) -> Collection: __ret = gca().pcolor( @@ -3915,7 +3915,7 @@ def pcolormesh( colorizer: Colorizer | None = None, shading: Literal["flat", "nearest", "gouraud", "auto"] | None = None, antialiased: bool = False, - data=None, + data: DataParamType = None, **kwargs, ) -> QuadMesh: __ret = gca().pcolormesh( @@ -3945,7 +3945,7 @@ def phase_spectrum( pad_to: int | None = None, sides: Literal["default", "onesided", "twosided"] | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray, Line2D]: return gca().phase_spectrum( @@ -3982,7 +3982,7 @@ def pie( *, normalize: bool = True, hatch: str | Sequence[str] | None = None, - data=None, + data: DataParamType = None, ) -> PieContainer: return gca().pie( x, @@ -4035,7 +4035,7 @@ def plot( *args: float | ArrayLike | str, scalex: bool = True, scaley: bool = True, - data=None, + data: DataParamType = None, **kwargs, ) -> list[Line2D]: return gca().plot( @@ -4054,9 +4054,9 @@ def psd( NFFT: int | None = None, Fs: float | None = None, Fc: int | None = None, - detrend: ( - Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] | None - ) = None, + detrend: Literal["none", "mean", "linear"] + | Callable[[ArrayLike], ArrayLike] + | None = None, window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = None, noverlap: int | None = None, pad_to: int | None = None, @@ -4064,7 +4064,7 @@ def psd( scale_by_freq: bool | None = None, return_line: bool | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: return gca().psd( @@ -4086,7 +4086,7 @@ def psd( # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_copy_docstring_and_deprecators(Axes.quiver) -def quiver(*args, data=None, **kwargs) -> Quiver: +def quiver(*args, data: DataParamType = None, **kwargs) -> Quiver: __ret = gca().quiver( *args, **({"data": data} if data is not None else {}), **kwargs ) @@ -4120,7 +4120,7 @@ def scatter( edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = None, colorizer: Colorizer | None = None, plotnonfinite: bool = False, - data=None, + data: DataParamType = None, **kwargs, ) -> PathCollection: __ret = gca().scatter( @@ -4164,9 +4164,9 @@ def specgram( NFFT: int | None = None, Fs: float | None = None, Fc: int | None = None, - detrend: ( - Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] | None - ) = None, + detrend: Literal["none", "mean", "linear"] + | Callable[[ArrayLike], ArrayLike] + | None = None, window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = None, noverlap: int | None = None, cmap: str | Colormap | None = None, @@ -4179,7 +4179,7 @@ def specgram( vmin: float | None = None, vmax: float | None = None, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray, np.ndarray, AxesImage]: __ret = gca().specgram( @@ -4255,7 +4255,7 @@ def stem( bottom: float = 0, label: str | None = None, orientation: Literal["vertical", "horizontal"] = "vertical", - data=None, + data: DataParamType = None, ) -> StemContainer: return gca().stem( *args, @@ -4276,7 +4276,7 @@ def step( y: ArrayLike, *args, where: Literal["pre", "post", "mid"] = "pre", - data=None, + data: DataParamType = None, **kwargs, ) -> list[Line2D]: return gca().step( @@ -4480,14 +4480,15 @@ def violinplot( showmedians: bool = False, quantiles: Sequence[float | Sequence[float]] | None = None, points: int = 100, - bw_method: ( - Literal["scott", "silverman"] | float | Callable[[GaussianKDE], float] | None - ) = None, + bw_method: Literal["scott", "silverman"] + | float + | Callable[[GaussianKDE], float] + | None = None, side: Literal["both", "low", "high"] = "both", facecolor: Sequence[ColorType] | ColorType | None = None, linecolor: Sequence[ColorType] | ColorType | None = None, *, - data=None, + data: DataParamType = None, ) -> dict[str, Collection]: return gca().violinplot( dataset, @@ -4518,7 +4519,7 @@ def vlines( linestyles: LineStyleType = "solid", label: str = "", *, - data=None, + data: DataParamType = None, **kwargs, ) -> LineCollection: return gca().vlines( @@ -4543,7 +4544,7 @@ def xcorr( usevlines: bool = True, maxlags: int = 10, *, - data=None, + data: DataParamType = None, **kwargs, ) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: return gca().xcorr( diff --git a/lib/matplotlib/typing.py b/lib/matplotlib/typing.py index 87016984da12..7fd9bdeefa8f 100644 --- a/lib/matplotlib/typing.py +++ b/lib/matplotlib/typing.py @@ -13,7 +13,7 @@ from collections.abc import Hashable, Sequence import pathlib from typing import Any, Literal, TypeAlias, TypeVar, Union -from collections.abc import Callable +from collections.abc import Callable, Mapping from . import path from ._enums import JoinStyle, CapStyle @@ -22,6 +22,9 @@ from .markers import MarkerStyle from .transforms import Bbox, Transform +DataParamType: TypeAlias = Mapping[str, Any] | None +"""The type of the *data* parameter in plotting functions.""" + RGBColorType: TypeAlias = tuple[float, float, float] | str """Any RGB color specification accepted by Matplotlib.""" From 71facf6ba367854a89d82d601193c683c32f36b7 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Fri, 10 Apr 2026 08:36:08 +0200 Subject: [PATCH 2/2] Run boilerplate with current version of black --- lib/matplotlib/pyplot.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 777bc4877aa9..65b257096cbc 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -3297,8 +3297,9 @@ def cohere( NFFT: int = 256, Fs: float = 2, Fc: int = 0, - detrend: Literal["none", "mean", "linear"] - | Callable[[ArrayLike], ArrayLike] = mlab.detrend_none, + detrend: ( + Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] + ) = mlab.detrend_none, window: Callable[[ArrayLike], ArrayLike] | ArrayLike = mlab.window_hanning, noverlap: int = 0, pad_to: int | None = None, @@ -3355,9 +3356,9 @@ def csd( NFFT: int | None = None, Fs: float | None = None, Fc: int | None = None, - detrend: Literal["none", "mean", "linear"] - | Callable[[ArrayLike], ArrayLike] - | None = None, + detrend: ( + Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] | None + ) = None, window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = None, noverlap: int | None = None, pad_to: int | None = None, @@ -4054,9 +4055,9 @@ def psd( NFFT: int | None = None, Fs: float | None = None, Fc: int | None = None, - detrend: Literal["none", "mean", "linear"] - | Callable[[ArrayLike], ArrayLike] - | None = None, + detrend: ( + Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] | None + ) = None, window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = None, noverlap: int | None = None, pad_to: int | None = None, @@ -4164,9 +4165,9 @@ def specgram( NFFT: int | None = None, Fs: float | None = None, Fc: int | None = None, - detrend: Literal["none", "mean", "linear"] - | Callable[[ArrayLike], ArrayLike] - | None = None, + detrend: ( + Literal["none", "mean", "linear"] | Callable[[ArrayLike], ArrayLike] | None + ) = None, window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = None, noverlap: int | None = None, cmap: str | Colormap | None = None, @@ -4480,10 +4481,9 @@ def violinplot( showmedians: bool = False, quantiles: Sequence[float | Sequence[float]] | None = None, points: int = 100, - bw_method: Literal["scott", "silverman"] - | float - | Callable[[GaussianKDE], float] - | None = None, + bw_method: ( + Literal["scott", "silverman"] | float | Callable[[GaussianKDE], float] | None + ) = None, side: Literal["both", "low", "high"] = "both", facecolor: Sequence[ColorType] | ColorType | None = None, linecolor: Sequence[ColorType] | ColorType | None = None,