Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a1f201

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 8a1f201

3 files changed

Lines changed: 99 additions & 94 deletions

File tree

lib/matplotlib/axes/_axes.pyi

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ from collections.abc import Callable, Iterable, Sequence
3737
from typing import Any, Literal, overload
3838
import numpy as np
3939
from numpy.typing import ArrayLike
40-
from matplotlib.typing import ColorType, MarkerType, LegendLocType, LineStyleType
40+
from matplotlib.typing import (
41+
ColorType, DataParamType, MarkerType, LegendLocType, LineStyleType)
4142
import pandas as pd
4243

4344

@@ -172,7 +173,7 @@ class Axes(_AxesBase):
172173
linestyles: LineStyleType = ...,
173174
*,
174175
label: str = ...,
175-
data=...,
176+
data: DataParamType = ...,
176177
**kwargs
177178
) -> LineCollection: ...
178179
def vlines(
@@ -184,7 +185,7 @@ class Axes(_AxesBase):
184185
linestyles: LineStyleType = ...,
185186
*,
186187
label: str = ...,
187-
data=...,
188+
data: DataParamType = ...,
188189
**kwargs
189190
) -> LineCollection: ...
190191
def eventplot(
@@ -198,22 +199,22 @@ class Axes(_AxesBase):
198199
colors: ColorType | Sequence[ColorType] | None = ...,
199200
alpha: float | Sequence[float] | None = ...,
200201
linestyles: LineStyleType | Sequence[LineStyleType] = ...,
201-
data=...,
202+
data: DataParamType = ...,
202203
**kwargs
203204
) -> EventCollection: ...
204205
def plot(
205206
self,
206207
*args: float | ArrayLike | str,
207208
scalex: bool = ...,
208209
scaley: bool = ...,
209-
data=...,
210+
data: DataParamType = ...,
210211
**kwargs
211212
) -> list[Line2D]: ...
212213
def loglog(self, *args, **kwargs) -> list[Line2D]: ...
213214
def semilogx(self, *args, **kwargs) -> list[Line2D]: ...
214215
def semilogy(self, *args, **kwargs) -> list[Line2D]: ...
215216
def acorr(
216-
self, x: ArrayLike, *, data=..., **kwargs
217+
self, x: ArrayLike, *, data: DataParamType = ..., **kwargs
217218
) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: ...
218219
def xcorr(
219220
self,
@@ -224,7 +225,7 @@ class Axes(_AxesBase):
224225
detrend: Callable[[ArrayLike], ArrayLike] = ...,
225226
usevlines: bool = ...,
226227
maxlags: int = ...,
227-
data=...,
228+
data: DataParamType = ...,
228229
**kwargs
229230
) -> tuple[np.ndarray, np.ndarray, LineCollection | Line2D, Line2D | None]: ...
230231
def step(
@@ -233,7 +234,7 @@ class Axes(_AxesBase):
233234
y: ArrayLike,
234235
*args,
235236
where: Literal["pre", "post", "mid"] = ...,
236-
data=...,
237+
data: DataParamType = ...,
237238
**kwargs
238239
) -> list[Line2D]: ...
239240
def bar(
@@ -244,7 +245,7 @@ class Axes(_AxesBase):
244245
bottom: float | ArrayLike | None = ...,
245246
*,
246247
align: Literal["center", "edge"] = ...,
247-
data=...,
248+
data: DataParamType = ...,
248249
**kwargs
249250
) -> BarContainer: ...
250251
def barh(
@@ -255,7 +256,7 @@ class Axes(_AxesBase):
255256
left: float | ArrayLike | None = ...,
256257
*,
257258
align: Literal["center", "edge"] = ...,
258-
data=...,
259+
data: DataParamType = ...,
259260
**kwargs
260261
) -> BarContainer: ...
261262
def bar_label(
@@ -274,7 +275,7 @@ class Axes(_AxesBase):
274275
yrange: tuple[float, float],
275276
align: Literal["bottom", "center", "top"] = ...,
276277
*,
277-
data=...,
278+
data: DataParamType = ...,
278279
**kwargs
279280
) -> PolyCollection: ...
280281
def grouped_bar(
@@ -299,7 +300,7 @@ class Axes(_AxesBase):
299300
bottom: float = ...,
300301
label: str | None = ...,
301302
orientation: Literal["vertical", "horizontal"] = ...,
302-
data=...,
303+
data: DataParamType = ...,
303304
) -> StemContainer: ...
304305

305306
# TODO: data kwarg preprocessor?
@@ -324,7 +325,7 @@ class Axes(_AxesBase):
324325
rotatelabels: bool = ...,
325326
normalize: bool = ...,
326327
hatch: str | Sequence[str] | None = ...,
327-
data=...,
328+
data: DataParamType = ...,
328329
) -> PieContainer: ...
329330
def pie_label(
330331
self,
@@ -356,7 +357,7 @@ class Axes(_AxesBase):
356357
xuplims: bool | ArrayLike = ...,
357358
errorevery: int | tuple[int, int] = ...,
358359
capthick: float | None = ...,
359-
data=...,
360+
data: DataParamType = ...,
360361
**kwargs
361362
) -> ErrorbarContainer: ...
362363
def boxplot(
@@ -391,7 +392,7 @@ class Axes(_AxesBase):
391392
zorder: float | None = ...,
392393
capwidths: float | ArrayLike | None = ...,
393394
label: Sequence[str] | None = ...,
394-
data=...,
395+
data: DataParamType = ...,
395396
) -> dict[str, Any]: ...
396397
def bxp(
397398
self,
@@ -436,7 +437,7 @@ class Axes(_AxesBase):
436437
edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = ...,
437438
colorizer: Colorizer | None = ...,
438439
plotnonfinite: bool = ...,
439-
data=...,
440+
data: DataParamType = ...,
440441
**kwargs
441442
) -> PathCollection: ...
442443
def hexbin(
@@ -461,7 +462,7 @@ class Axes(_AxesBase):
461462
mincnt: int | None = ...,
462463
marginals: bool = ...,
463464
colorizer: Colorizer | None = ...,
464-
data=...,
465+
data: DataParamType = ...,
465466
**kwargs
466467
) -> PolyCollection: ...
467468
def arrow(
@@ -470,9 +471,9 @@ class Axes(_AxesBase):
470471
def quiverkey(
471472
self, Q: Quiver, X: float, Y: float, U: float, label: str, **kwargs
472473
) -> 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]: ...
474+
def quiver(self, *args, data: DataParamType = ..., **kwargs) -> Quiver: ...
475+
def barbs(self, *args, data: DataParamType = ..., **kwargs) -> Barbs: ...
476+
def fill(self, *args, data: DataParamType = ..., **kwargs) -> list[Polygon]: ...
476477
def fill_between(
477478
self,
478479
x: ArrayLike,
@@ -482,7 +483,7 @@ class Axes(_AxesBase):
482483
interpolate: bool = ...,
483484
step: Literal["pre", "post", "mid"] | None = ...,
484485
*,
485-
data=...,
486+
data: DataParamType = ...,
486487
**kwargs
487488
) -> FillBetweenPolyCollection: ...
488489
def fill_betweenx(
@@ -494,7 +495,7 @@ class Axes(_AxesBase):
494495
step: Literal["pre", "post", "mid"] | None = ...,
495496
interpolate: bool = ...,
496497
*,
497-
data=...,
498+
data: DataParamType = ...,
498499
**kwargs
499500
) -> FillBetweenPolyCollection: ...
500501
def imshow(
@@ -516,7 +517,7 @@ class Axes(_AxesBase):
516517
filterrad: float = ...,
517518
resample: bool | None = ...,
518519
url: str | None = ...,
519-
data=...,
520+
data: DataParamType = ...,
520521
**kwargs
521522
) -> AxesImage: ...
522523
def pcolor(
@@ -529,7 +530,7 @@ class Axes(_AxesBase):
529530
vmin: float | None = ...,
530531
vmax: float | None = ...,
531532
colorizer: Colorizer | None = ...,
532-
data=...,
533+
data: DataParamType = ...,
533534
**kwargs
534535
) -> Collection: ...
535536
def pcolormesh(
@@ -543,7 +544,7 @@ class Axes(_AxesBase):
543544
colorizer: Colorizer | None = ...,
544545
shading: Literal["flat", "nearest", "gouraud", "auto"] | None = ...,
545546
antialiased: bool = ...,
546-
data=...,
547+
data: DataParamType = ...,
547548
**kwargs
548549
) -> QuadMesh: ...
549550
def pcolorfast(
@@ -555,11 +556,11 @@ class Axes(_AxesBase):
555556
vmin: float | None = ...,
556557
vmax: float | None = ...,
557558
colorizer: Colorizer | None = ...,
558-
data=...,
559+
data: DataParamType = ...,
559560
**kwargs
560561
) -> AxesImage | PcolorImage | QuadMesh: ...
561-
def contour(self, *args, data=..., **kwargs) -> QuadContourSet: ...
562-
def contourf(self, *args, data=..., **kwargs) -> QuadContourSet: ...
562+
def contour(self, *args, data: DataParamType = ..., **kwargs) -> QuadContourSet: ...
563+
def contourf(self, *args, data: DataParamType = ..., **kwargs) -> QuadContourSet: ...
563564
def clabel(
564565
self, CS: ContourSet, levels: ArrayLike | None = ..., **kwargs
565566
) -> list[Text]: ...
@@ -581,7 +582,7 @@ class Axes(_AxesBase):
581582
color: ColorType | Sequence[ColorType] | None = ...,
582583
label: str | Sequence[str] | None = ...,
583584
stacked: bool = ...,
584-
data=...,
585+
data: DataParamType = ...,
585586
**kwargs
586587
) -> tuple[
587588
np.ndarray | list[np.ndarray],
@@ -596,7 +597,7 @@ class Axes(_AxesBase):
596597
orientation: Literal["vertical", "horizontal"] = ...,
597598
baseline: float | ArrayLike | None = ...,
598599
fill: bool = ...,
599-
data=...,
600+
data: DataParamType = ...,
600601
**kwargs
601602
) -> StepPatch: ...
602603
def hist2d(
@@ -614,7 +615,7 @@ class Axes(_AxesBase):
614615
weights: ArrayLike | None = ...,
615616
cmin: float | None = ...,
616617
cmax: float | None = ...,
617-
data=...,
618+
data: DataParamType = ...,
618619
**kwargs
619620
) -> tuple[np.ndarray, np.ndarray, np.ndarray, QuadMesh]: ...
620621
def ecdf(
@@ -625,7 +626,7 @@ class Axes(_AxesBase):
625626
complementary: bool=...,
626627
orientation: Literal["vertical", "horizontal"]=...,
627628
compress: bool=...,
628-
data=...,
629+
data: DataParamType = ...,
629630
**kwargs
630631
) -> Line2D: ...
631632
def psd(
@@ -644,7 +645,7 @@ class Axes(_AxesBase):
644645
sides: Literal["default", "onesided", "twosided"] | None = ...,
645646
scale_by_freq: bool | None = ...,
646647
return_line: bool | None = ...,
647-
data=...,
648+
data: DataParamType = ...,
648649
**kwargs
649650
) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: ...
650651
def csd(
@@ -664,7 +665,7 @@ class Axes(_AxesBase):
664665
sides: Literal["default", "onesided", "twosided"] | None = ...,
665666
scale_by_freq: bool | None = ...,
666667
return_line: bool | None = ...,
667-
data=...,
668+
data: DataParamType = ...,
668669
**kwargs
669670
) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, Line2D]: ...
670671
def magnitude_spectrum(
@@ -677,7 +678,7 @@ class Axes(_AxesBase):
677678
pad_to: int | None = ...,
678679
sides: Literal["default", "onesided", "twosided"] | None = ...,
679680
scale: Literal["default", "linear", "dB"] | None = ...,
680-
data=...,
681+
data: DataParamType = ...,
681682
**kwargs
682683
) -> tuple[np.ndarray, np.ndarray, Line2D]: ...
683684
def angle_spectrum(
@@ -689,7 +690,7 @@ class Axes(_AxesBase):
689690
window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ...,
690691
pad_to: int | None = ...,
691692
sides: Literal["default", "onesided", "twosided"] | None = ...,
692-
data=...,
693+
data: DataParamType = ...,
693694
**kwargs
694695
) -> tuple[np.ndarray, np.ndarray, Line2D]: ...
695696
def phase_spectrum(
@@ -701,7 +702,7 @@ class Axes(_AxesBase):
701702
window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ...,
702703
pad_to: int | None = ...,
703704
sides: Literal["default", "onesided", "twosided"] | None = ...,
704-
data=...,
705+
data: DataParamType = ...,
705706
**kwargs
706707
) -> tuple[np.ndarray, np.ndarray, Line2D]: ...
707708
def cohere(
@@ -719,7 +720,7 @@ class Axes(_AxesBase):
719720
pad_to: int | None = ...,
720721
sides: Literal["default", "onesided", "twosided"] = ...,
721722
scale_by_freq: bool | None = ...,
722-
data=...,
723+
data: DataParamType = ...,
723724
**kwargs
724725
) -> tuple[np.ndarray, np.ndarray]: ...
725726
def specgram(
@@ -743,7 +744,7 @@ class Axes(_AxesBase):
743744
scale: Literal["default", "linear", "dB"] | None = ...,
744745
vmin: float | None = ...,
745746
vmax: float | None = ...,
746-
data=...,
747+
data: DataParamType = ...,
747748
**kwargs
748749
) -> tuple[np.ndarray, np.ndarray, np.ndarray, AxesImage]: ...
749750
def spy(
@@ -778,7 +779,7 @@ class Axes(_AxesBase):
778779
side: Literal["both", "low", "high"] = ...,
779780
facecolor: Sequence[ColorType] | ColorType | None = ...,
780781
linecolor: Sequence[ColorType] | ColorType | None = ...,
781-
data=...,
782+
data: DataParamType = ...,
782783
) -> dict[str, Collection]: ...
783784
def violin(
784785
self,

0 commit comments

Comments
 (0)