Skip to content

Commit be5d96c

Browse files
committed
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.
1 parent a7fc902 commit be5d96c

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

lib/matplotlib/axes/_axes.pyi

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import matplotlib.stackplot as mstack
3333
import matplotlib.streamplot as mstream
3434

3535
import PIL.Image
36-
from collections.abc import Callable, Iterable, Sequence
36+
from collections.abc import Callable, Iterable, Mapping, Sequence
3737
from typing import Any, Literal, overload
3838
import numpy as np
3939
from numpy.typing import ArrayLike
@@ -172,7 +172,7 @@ class Axes(_AxesBase):
172172
linestyles: LineStyleType = ...,
173173
*,
174174
label: str = ...,
175-
data=...,
175+
data: Mapping[str, Any] = ...,
176176
**kwargs
177177
) -> LineCollection: ...
178178
def vlines(
@@ -184,7 +184,7 @@ class Axes(_AxesBase):
184184
linestyles: LineStyleType = ...,
185185
*,
186186
label: str = ...,
187-
data=...,
187+
data: Mapping[str, Any] = ...,
188188
**kwargs
189189
) -> LineCollection: ...
190190
def eventplot(
@@ -198,22 +198,22 @@ class Axes(_AxesBase):
198198
colors: ColorType | Sequence[ColorType] | None = ...,
199199
alpha: float | Sequence[float] | None = ...,
200200
linestyles: LineStyleType | Sequence[LineStyleType] = ...,
201-
data=...,
201+
data: Mapping[str, Any] = ...,
202202
**kwargs
203203
) -> EventCollection: ...
204204
def plot(
205205
self,
206206
*args: float | ArrayLike | str,
207207
scalex: bool = ...,
208208
scaley: bool = ...,
209-
data=...,
209+
data: Mapping[str, Any] = ...,
210210
**kwargs
211211
) -> list[Line2D]: ...
212212
def loglog(self, *args, **kwargs) -> list[Line2D]: ...
213213
def semilogx(self, *args, **kwargs) -> list[Line2D]: ...
214214
def semilogy(self, *args, **kwargs) -> list[Line2D]: ...
215215
def acorr(
216-
self, x: ArrayLike, *, data=..., **kwargs
216+
self, x: ArrayLike, *, data: Mapping[str, Any] = ..., **kwargs
217217
) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: ...
218218
def xcorr(
219219
self,
@@ -224,7 +224,7 @@ class Axes(_AxesBase):
224224
detrend: Callable[[ArrayLike], ArrayLike] = ...,
225225
usevlines: bool = ...,
226226
maxlags: int = ...,
227-
data=...,
227+
data: Mapping[str, Any] = ...,
228228
**kwargs
229229
) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: ...
230230
def step(
@@ -233,7 +233,7 @@ class Axes(_AxesBase):
233233
y: ArrayLike,
234234
*args,
235235
where: Literal["pre", "post", "mid"] = ...,
236-
data=...,
236+
data: Mapping[str, Any] = ...,
237237
**kwargs
238238
) -> list[Line2D]: ...
239239
def bar(
@@ -244,7 +244,7 @@ class Axes(_AxesBase):
244244
bottom: float | ArrayLike | None = ...,
245245
*,
246246
align: Literal["center", "edge"] = ...,
247-
data=...,
247+
data: Mapping[str, Any] = ...,
248248
**kwargs
249249
) -> BarContainer: ...
250250
def barh(
@@ -255,7 +255,7 @@ class Axes(_AxesBase):
255255
left: float | ArrayLike | None = ...,
256256
*,
257257
align: Literal["center", "edge"] = ...,
258-
data=...,
258+
data: Mapping[str, Any] = ...,
259259
**kwargs
260260
) -> BarContainer: ...
261261
def bar_label(
@@ -274,7 +274,7 @@ class Axes(_AxesBase):
274274
yrange: tuple[float, float],
275275
align: Literal["bottom", "center", "top"] = ...,
276276
*,
277-
data=...,
277+
data: Mapping[str, Any] = ...,
278278
**kwargs
279279
) -> PolyCollection: ...
280280
def grouped_bar(
@@ -299,7 +299,7 @@ class Axes(_AxesBase):
299299
bottom: float = ...,
300300
label: str | None = ...,
301301
orientation: Literal["vertical", "horizontal"] = ...,
302-
data=...,
302+
data: Mapping[str, Any] = ...,
303303
) -> StemContainer: ...
304304

305305
# TODO: data kwarg preprocessor?
@@ -324,7 +324,7 @@ class Axes(_AxesBase):
324324
rotatelabels: bool = ...,
325325
normalize: bool = ...,
326326
hatch: str | Sequence[str] | None = ...,
327-
data=...,
327+
data: Mapping[str, Any] = ...,
328328
) -> PieContainer: ...
329329
def pie_label(
330330
self,
@@ -356,7 +356,7 @@ class Axes(_AxesBase):
356356
xuplims: bool | ArrayLike = ...,
357357
errorevery: int | tuple[int, int] = ...,
358358
capthick: float | None = ...,
359-
data=...,
359+
data: Mapping[str, Any] = ...,
360360
**kwargs
361361
) -> ErrorbarContainer: ...
362362
def boxplot(
@@ -391,7 +391,7 @@ class Axes(_AxesBase):
391391
zorder: float | None = ...,
392392
capwidths: float | ArrayLike | None = ...,
393393
label: Sequence[str] | None = ...,
394-
data=...,
394+
data: Mapping[str, Any] = ...,
395395
) -> dict[str, Any]: ...
396396
def bxp(
397397
self,
@@ -436,7 +436,7 @@ class Axes(_AxesBase):
436436
edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = ...,
437437
colorizer: Colorizer | None = ...,
438438
plotnonfinite: bool = ...,
439-
data=...,
439+
data: Mapping[str, Any] = ...,
440440
**kwargs
441441
) -> PathCollection: ...
442442
def hexbin(
@@ -461,7 +461,7 @@ class Axes(_AxesBase):
461461
mincnt: int | None = ...,
462462
marginals: bool = ...,
463463
colorizer: Colorizer | None = ...,
464-
data=...,
464+
data: Mapping[str, Any] = ...,
465465
**kwargs
466466
) -> PolyCollection: ...
467467
def arrow(
@@ -470,9 +470,9 @@ class Axes(_AxesBase):
470470
def quiverkey(
471471
self, Q: Quiver, X: float, Y: float, U: float, label: str, **kwargs
472472
) -> QuiverKey: ...
473-
def quiver(self, *args, data=..., **kwargs) -> Quiver: ...
474-
def barbs(self, *args, data=..., **kwargs) -> Barbs: ...
475-
def fill(self, *args, data=..., **kwargs) -> list[Polygon]: ...
473+
def quiver(self, *args, data: Mapping[str, Any] = ..., **kwargs) -> Quiver: ...
474+
def barbs(self, *args, data: Mapping[str, Any] = ..., **kwargs) -> Barbs: ...
475+
def fill(self, *args, data: Mapping[str, Any] = ..., **kwargs) -> list[Polygon]: ...
476476
def fill_between(
477477
self,
478478
x: ArrayLike,
@@ -482,7 +482,7 @@ class Axes(_AxesBase):
482482
interpolate: bool = ...,
483483
step: Literal["pre", "post", "mid"] | None = ...,
484484
*,
485-
data=...,
485+
data: Mapping[str, Any] = ...,
486486
**kwargs
487487
) -> FillBetweenPolyCollection: ...
488488
def fill_betweenx(
@@ -494,7 +494,7 @@ class Axes(_AxesBase):
494494
step: Literal["pre", "post", "mid"] | None = ...,
495495
interpolate: bool = ...,
496496
*,
497-
data=...,
497+
data: Mapping[str, Any] = ...,
498498
**kwargs
499499
) -> FillBetweenPolyCollection: ...
500500
def imshow(
@@ -516,7 +516,7 @@ class Axes(_AxesBase):
516516
filterrad: float = ...,
517517
resample: bool | None = ...,
518518
url: str | None = ...,
519-
data=...,
519+
data: Mapping[str, Any] = ...,
520520
**kwargs
521521
) -> AxesImage: ...
522522
def pcolor(
@@ -529,7 +529,7 @@ class Axes(_AxesBase):
529529
vmin: float | None = ...,
530530
vmax: float | None = ...,
531531
colorizer: Colorizer | None = ...,
532-
data=...,
532+
data: Mapping[str, Any] = ...,
533533
**kwargs
534534
) -> Collection: ...
535535
def pcolormesh(
@@ -543,7 +543,7 @@ class Axes(_AxesBase):
543543
colorizer: Colorizer | None = ...,
544544
shading: Literal["flat", "nearest", "gouraud", "auto"] | None = ...,
545545
antialiased: bool = ...,
546-
data=...,
546+
data: Mapping[str, Any] = ...,
547547
**kwargs
548548
) -> QuadMesh: ...
549549
def pcolorfast(
@@ -555,11 +555,11 @@ class Axes(_AxesBase):
555555
vmin: float | None = ...,
556556
vmax: float | None = ...,
557557
colorizer: Colorizer | None = ...,
558-
data=...,
558+
data: Mapping[str, Any] = ...,
559559
**kwargs
560560
) -> AxesImage | PcolorImage | QuadMesh: ...
561-
def contour(self, *args, data=..., **kwargs) -> QuadContourSet: ...
562-
def contourf(self, *args, data=..., **kwargs) -> QuadContourSet: ...
561+
def contour(self, *args, data: Mapping[str, Any] = ..., **kwargs) -> QuadContourSet: ...
562+
def contourf(self, *args, data: Mapping[str, Any] = ..., **kwargs) -> QuadContourSet: ...
563563
def clabel(
564564
self, CS: ContourSet, levels: ArrayLike | None = ..., **kwargs
565565
) -> list[Text]: ...
@@ -581,7 +581,7 @@ class Axes(_AxesBase):
581581
color: ColorType | Sequence[ColorType] | None = ...,
582582
label: str | Sequence[str] | None = ...,
583583
stacked: bool = ...,
584-
data=...,
584+
data: Mapping[str, Any] = ...,
585585
**kwargs
586586
) -> tuple[
587587
np.ndarray | list[np.ndarray],
@@ -596,7 +596,7 @@ class Axes(_AxesBase):
596596
orientation: Literal["vertical", "horizontal"] = ...,
597597
baseline: float | ArrayLike | None = ...,
598598
fill: bool = ...,
599-
data=...,
599+
data: Mapping[str, Any] = ...,
600600
**kwargs
601601
) -> StepPatch: ...
602602
def hist2d(
@@ -614,7 +614,7 @@ class Axes(_AxesBase):
614614
weights: ArrayLike | None = ...,
615615
cmin: float | None = ...,
616616
cmax: float | None = ...,
617-
data=...,
617+
data: Mapping[str, Any] = ...,
618618
**kwargs
619619
) -> tuple[np.ndarray, np.ndarray, np.ndarray, QuadMesh]: ...
620620
def ecdf(
@@ -625,7 +625,7 @@ class Axes(_AxesBase):
625625
complementary: bool=...,
626626
orientation: Literal["vertical", "horizontal"]=...,
627627
compress: bool=...,
628-
data=...,
628+
data: Mapping[str, Any] = ...,
629629
**kwargs
630630
) -> Line2D: ...
631631
def psd(
@@ -644,7 +644,7 @@ class Axes(_AxesBase):
644644
sides: Literal["default", "onesided", "twosided"] | None = ...,
645645
scale_by_freq: bool | None = ...,
646646
return_line: bool | None = ...,
647-
data=...,
647+
data: Mapping[str, Any] = ...,
648648
**kwargs
649649
) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: ...
650650
def csd(
@@ -664,7 +664,7 @@ class Axes(_AxesBase):
664664
sides: Literal["default", "onesided", "twosided"] | None = ...,
665665
scale_by_freq: bool | None = ...,
666666
return_line: bool | None = ...,
667-
data=...,
667+
data: Mapping[str, Any] = ...,
668668
**kwargs
669669
) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: ...
670670
def magnitude_spectrum(
@@ -677,7 +677,7 @@ class Axes(_AxesBase):
677677
pad_to: int | None = ...,
678678
sides: Literal["default", "onesided", "twosided"] | None = ...,
679679
scale: Literal["default", "linear", "dB"] | None = ...,
680-
data=...,
680+
data: Mapping[str, Any] = ...,
681681
**kwargs
682682
) -> tuple[np.ndarray, np.ndarray, Line2D]: ...
683683
def angle_spectrum(
@@ -689,7 +689,7 @@ class Axes(_AxesBase):
689689
window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ...,
690690
pad_to: int | None = ...,
691691
sides: Literal["default", "onesided", "twosided"] | None = ...,
692-
data=...,
692+
data: Mapping[str, Any] = ...,
693693
**kwargs
694694
) -> tuple[np.ndarray, np.ndarray, Line2D]: ...
695695
def phase_spectrum(
@@ -701,7 +701,7 @@ class Axes(_AxesBase):
701701
window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ...,
702702
pad_to: int | None = ...,
703703
sides: Literal["default", "onesided", "twosided"] | None = ...,
704-
data=...,
704+
data: Mapping[str, Any] = ...,
705705
**kwargs
706706
) -> tuple[np.ndarray, np.ndarray, Line2D]: ...
707707
def cohere(
@@ -719,7 +719,7 @@ class Axes(_AxesBase):
719719
pad_to: int | None = ...,
720720
sides: Literal["default", "onesided", "twosided"] = ...,
721721
scale_by_freq: bool | None = ...,
722-
data=...,
722+
data: Mapping[str, Any] = ...,
723723
**kwargs
724724
) -> tuple[np.ndarray, np.ndarray]: ...
725725
def specgram(
@@ -743,7 +743,7 @@ class Axes(_AxesBase):
743743
scale: Literal["default", "linear", "dB"] | None = ...,
744744
vmin: float | None = ...,
745745
vmax: float | None = ...,
746-
data=...,
746+
data: Mapping[str, Any] = ...,
747747
**kwargs
748748
) -> tuple[np.ndarray, np.ndarray, np.ndarray, AxesImage]: ...
749749
def spy(
@@ -778,7 +778,7 @@ class Axes(_AxesBase):
778778
side: Literal["both", "low", "high"] = ...,
779779
facecolor: Sequence[ColorType] | ColorType | None = ...,
780780
linecolor: Sequence[ColorType] | ColorType | None = ...,
781-
data=...,
781+
data: Mapping[str, Any] = ...,
782782
) -> dict[str, Collection]: ...
783783
def violin(
784784
self,

0 commit comments

Comments
 (0)