1
+ import os
1
2
from _typeshed import Incomplete
2
3
from collections .abc import Callable , Generator , Iterable , Mapping
3
- from typing import Any , TypeVar
4
- from typing_extensions import Concatenate , Literal , ParamSpec , Self
4
+ from typing import IO , Any , TypeVar
5
+ from typing_extensions import Concatenate , Literal , ParamSpec , Self , TypeAlias
5
6
7
+ import numpy as np
6
8
from matplotlib .artist import Artist
7
9
from matplotlib .axes import Axes
8
- from matplotlib .colors import Colormap
10
+ from matplotlib .backend_bases import MouseEvent , RendererBase
11
+ from matplotlib .colors import Colormap , Normalize
9
12
from matplotlib .figure import Figure
13
+ from matplotlib .font_manager import FontProperties
14
+ from matplotlib .gridspec import SubplotSpec
10
15
from matplotlib .legend import Legend
16
+ from matplotlib .patches import Patch
17
+ from matplotlib .path import Path as mpl_Path
18
+ from matplotlib .patheffects import AbstractPathEffect
19
+ from matplotlib .scale import ScaleBase
11
20
from matplotlib .text import Text
12
- from matplotlib .typing import ColorType
13
- from numpy .typing import NDArray
21
+ from matplotlib .transforms import Bbox , BboxBase , Transform , TransformedPath
22
+ from matplotlib .typing import ColorType , LineStyleType , MarkerType
23
+ from numpy .typing import ArrayLike , NDArray
14
24
from pandas import DataFrame , Series
15
25
26
+ from ._core .typing import ColumnName , DataSource , _SupportsDataFrame
16
27
from .palettes import _RGBColorPalette
17
- from .utils import _Palette
28
+ from .utils import _DataSourceWideForm , _Palette , _Vector
18
29
19
30
__all__ = ["FacetGrid" , "PairGrid" , "JointGrid" , "pairplot" , "jointplot" ]
20
31
21
32
_P = ParamSpec ("_P" )
22
33
_R = TypeVar ("_R" )
23
34
35
+ _LiteralFont : TypeAlias = Literal ["xx-small" , "x-small" , "small" , "medium" , "large" , "x-large" , "xx-large" ]
36
+
24
37
class _BaseGrid :
25
- def set (self , ** kwargs : Incomplete ) -> Self : ... # **kwargs are passed to `matplotlib.axes.Axes.set`
38
+ def set (
39
+ self ,
40
+ * ,
41
+ # Keywords follow `matplotlib.axes.Axes.set`. Each keyword <KW> corresponds to a `set_<KW>` method
42
+ adjustable : Literal ["box" , "datalim" ] = ...,
43
+ agg_filter : Callable [[ArrayLike , float ], tuple [NDArray [np .floating [Any ]], float , float ]] | None = ...,
44
+ alpha : float | None = ...,
45
+ anchor : str | tuple [float , float ] = ...,
46
+ animated : bool = ...,
47
+ aspect : float | Literal ["auto" , "equal" ] = ...,
48
+ autoscale_on : bool = ...,
49
+ autoscalex_on : bool = ...,
50
+ autoscaley_on : bool = ...,
51
+ axes_locator : Callable [[Axes , RendererBase ], Bbox ] = ...,
52
+ axisbelow : bool | Literal ["line" ] = ...,
53
+ box_aspect : float | None = ...,
54
+ clip_box : BboxBase | None = ...,
55
+ clip_on : bool = ...,
56
+ clip_path : Patch | mpl_Path | TransformedPath | None = ...,
57
+ facecolor : ColorType | None = ...,
58
+ frame_on : bool = ...,
59
+ gid : str | None = ...,
60
+ in_layout : bool = ...,
61
+ label : object = ...,
62
+ mouseover : bool = ...,
63
+ navigate : bool = ...,
64
+ path_effects : list [AbstractPathEffect ] = ...,
65
+ picker : bool | float | Callable [[Artist , MouseEvent ], tuple [bool , dict [Any , Any ]]] | None = ...,
66
+ position : Bbox | tuple [float , float , float , float ] = ...,
67
+ prop_cycle : Incomplete = ..., # TODO: use cycler.Cycler when cycler gets typed
68
+ rasterization_zorder : float | None = ...,
69
+ rasterized : bool = ...,
70
+ sketch_params : float | None = ...,
71
+ snap : bool | None = ...,
72
+ subplotspec : SubplotSpec = ...,
73
+ title : str = ...,
74
+ transform : Transform | None = ...,
75
+ url : str | None = ...,
76
+ visible : bool = ...,
77
+ xbound : float | None | tuple [float | None , float | None ] = ...,
78
+ xlabel : str = ...,
79
+ xlim : float | None | tuple [float | None , float | None ] = ...,
80
+ xmargin : float = ...,
81
+ xscale : str | ScaleBase = ...,
82
+ xticklabels : Iterable [str | Text ] = ...,
83
+ xticks : ArrayLike = ...,
84
+ ybound : float | None | tuple [float | None , float | None ] = ...,
85
+ ylabel : str = ...,
86
+ ylim : float | None | tuple [float | None , float | None ] = ...,
87
+ ymargin : float = ...,
88
+ yscale : str | ScaleBase = ...,
89
+ yticklabels : Iterable [str | Text ] = ...,
90
+ yticks : ArrayLike = ...,
91
+ zorder : float = ...,
92
+ ** kwargs : Any ,
93
+ ) -> Self : ...
26
94
@property
27
95
def fig (self ) -> Figure : ...
28
96
@property
29
97
def figure (self ) -> Figure : ...
30
98
def apply (self , func : Callable [Concatenate [Self , _P ], object ], * args : _P .args , ** kwargs : _P .kwargs ) -> Self : ...
31
99
def pipe (self , func : Callable [Concatenate [Self , _P ], _R ], * args : _P .args , ** kwargs : _P .kwargs ) -> _R : ...
32
100
def savefig (
33
- self , * args : Incomplete , ** kwargs : Incomplete
34
- ) -> None : ... # *args and **kwargs are passed to `matplotlib.figure.Figure.savefig`
101
+ self ,
102
+ # Signature follows `matplotlib.figure.Figure.savefig`
103
+ fname : str | os .PathLike [Any ] | IO [Any ],
104
+ * ,
105
+ transparent : bool | None = None ,
106
+ dpi : float | Literal ["figure" ] | None = 96 ,
107
+ facecolor : ColorType | Literal ["auto" ] | None = "auto" ,
108
+ edgecolor : ColorType | Literal ["auto" ] | None = "auto" ,
109
+ orientation : Literal ["landscape" , "portrait" ] = "portrait" ,
110
+ format : str | None = None ,
111
+ bbox_inches : Literal ["tight" ] | Bbox | None = "tight" ,
112
+ pad_inches : float | Literal ["layout" ] | None = None ,
113
+ backend : str | None = None ,
114
+ ** kwargs : Any ,
115
+ ) -> None : ...
35
116
36
117
class Grid (_BaseGrid ):
37
118
def __init__ (self ) -> None : ...
38
119
def tight_layout (
39
- self , * args : Incomplete , ** kwargs : Incomplete
40
- ) -> Self : ... # *args and **kwargs are passed to `matplotlib.figure.Figure.tight_layout`
120
+ self ,
121
+ * ,
122
+ # Keywords follow `matplotlib.figure.Figure.tight_layout`
123
+ pad : float = 1.08 ,
124
+ h_pad : float | None = None ,
125
+ w_pad : float | None = None ,
126
+ rect : tuple [float , float , float , float ] | None = None ,
127
+ ) -> Self : ...
41
128
def add_legend (
42
129
self ,
43
- legend_data : Mapping [Any , Artist ] | None = None , # cannot use precise key type because of invariant Mapping keys
130
+ # Cannot use precise key type with union for legend_data because of invariant Mapping keys
131
+ legend_data : Mapping [Any , Artist ] | None = None ,
44
132
title : str | None = None ,
45
133
label_order : list [str ] | None = None ,
46
134
adjust_subtitles : bool = False ,
47
- ** kwargs : Incomplete , # **kwargs are passed to `matplotlib.figure.Figure.legend`
135
+ * ,
136
+ # Keywords follow `matplotlib.legend.Legend`
137
+ loc : str | int | tuple [float , float ] | None = None ,
138
+ numpoints : int | None = None ,
139
+ markerscale : float | None = None ,
140
+ markerfirst : bool = True ,
141
+ reverse : bool = False ,
142
+ scatterpoints : int | None = None ,
143
+ scatteryoffsets : Iterable [float ] | None = None ,
144
+ prop : FontProperties | dict [str , Any ] | None = None ,
145
+ fontsize : int | _LiteralFont | None = None ,
146
+ labelcolor : str | Iterable [str ] | None = None ,
147
+ borderpad : float | None = None ,
148
+ labelspacing : float | None = None ,
149
+ handlelength : float | None = None ,
150
+ handleheight : float | None = None ,
151
+ handletextpad : float | None = None ,
152
+ borderaxespad : float | None = None ,
153
+ columnspacing : float | None = None ,
154
+ ncols : int = 1 ,
155
+ mode : Literal ["expand" ] | None = None ,
156
+ fancybox : bool | None = None ,
157
+ shadow : bool | dict [str , float ] | None = None ,
158
+ title_fontsize : int | _LiteralFont | None = None ,
159
+ framealpha : float | None = None ,
160
+ edgecolor : ColorType | None = None ,
161
+ facecolor : ColorType | None = None ,
162
+ bbox_to_anchor : BboxBase | tuple [float , float ] | tuple [float , float , float , float ] | None = None ,
163
+ bbox_transform : Transform | None = None ,
164
+ frameon : bool | None = None ,
165
+ handler_map : None = None ,
166
+ title_fontproperties : FontProperties | None = None ,
167
+ alignment : Literal ["center" , "left" , "right" ] = "center" ,
168
+ ncol : int = 1 ,
169
+ draggable : bool = False ,
48
170
) -> Self : ...
49
171
@property
50
172
def legend (self ) -> Legend | None : ...
51
173
def tick_params (
52
- self , axis : Literal ["x" , "y" , "both" ] = "both" , ** kwargs : Incomplete
53
- ) -> Self : ... # **kwargs are passed to `matplotlib.axes.Axes.tick_params`
174
+ self ,
175
+ axis : Literal ["x" , "y" , "both" ] = "both" ,
176
+ * ,
177
+ # Keywords follow `matplotlib.axes.Axes.tick_params`
178
+ which : Literal ["major" , "minor" , "both" ] = "major" ,
179
+ reset : bool = False ,
180
+ direction : Literal ["in" , "out" , "inout" ] = ...,
181
+ length : float = ...,
182
+ width : float = ...,
183
+ color : ColorType = ...,
184
+ pad : float = ...,
185
+ labelsize : float | str = ...,
186
+ labelcolor : ColorType = ...,
187
+ labelfontfamily : str = ...,
188
+ colors : ColorType = ...,
189
+ zorder : float = ...,
190
+ bottom : bool = ...,
191
+ top : bool = ...,
192
+ left : bool = ...,
193
+ right : bool = ...,
194
+ labelbottom : bool = ...,
195
+ labeltop : bool = ...,
196
+ labelleft : bool = ...,
197
+ labelright : bool = ...,
198
+ labelrotation : float = ...,
199
+ grid_color : ColorType = ...,
200
+ grid_alpha : float = ...,
201
+ grid_linewidth : float = ...,
202
+ grid_linestyle : str = ...,
203
+ ** kwargs : Any ,
204
+ ) -> Self : ...
54
205
55
206
class FacetGrid (Grid ):
56
207
data : DataFrame
@@ -60,7 +211,7 @@ class FacetGrid(Grid):
60
211
hue_kws : dict [str , Any ]
61
212
def __init__ (
62
213
self ,
63
- data : DataFrame ,
214
+ data : DataFrame | _SupportsDataFrame ,
64
215
* ,
65
216
row : str | None = None ,
66
217
col : str | None = None ,
@@ -88,10 +239,10 @@ class FacetGrid(Grid):
88
239
def map (self , func : Callable [..., object ], * args : str , ** kwargs : Any ) -> Self : ...
89
240
def map_dataframe (self , func : Callable [..., object ], * args : str , ** kwargs : Any ) -> Self : ...
90
241
def facet_axis (self , row_i : int , col_j : int , modify_state : bool = True ) -> Axes : ...
242
+ # `despine` should be kept roughly in line with `seaborn.utils.despine`
91
243
def despine (
92
244
self ,
93
245
* ,
94
- fig : Figure | None = None ,
95
246
ax : Axes | None = None ,
96
247
top : bool = True ,
97
248
right : bool = True ,
@@ -111,7 +262,13 @@ class FacetGrid(Grid):
111
262
self , template : str | None = None , row_template : str | None = None , col_template : str | None = None , ** kwargs : Any
112
263
) -> Self : ...
113
264
def refline (
114
- self , * , x : float | None = None , y : float | None = None , color : ColorType = ".5" , linestyle : str = "--" , ** line_kws : Any
265
+ self ,
266
+ * ,
267
+ x : float | None = None ,
268
+ y : float | None = None ,
269
+ color : ColorType = ".5" ,
270
+ linestyle : LineStyleType = "--" ,
271
+ ** line_kws : Any ,
115
272
) -> Self : ...
116
273
@property
117
274
def axes (self ) -> NDArray [Incomplete ]: ... # array of `Axes`
@@ -127,15 +284,15 @@ class PairGrid(Grid):
127
284
axes : NDArray [Incomplete ] # two-dimensional array of `Axes`
128
285
data : DataFrame
129
286
diag_sharey : bool
130
- diag_vars : NDArray [ Incomplete ] | None # array of `str`
131
- diag_axes : NDArray [ Incomplete ] | None # array of `Axes`
287
+ diag_vars : list [ str ] | None
288
+ diag_axes : list [ Axes ] | None
132
289
hue_names : list [str ]
133
- hue_vals : Series [Incomplete ]
290
+ hue_vals : Series [Any ]
134
291
hue_kws : dict [str , Any ]
135
292
palette : _RGBColorPalette
136
293
def __init__ (
137
294
self ,
138
- data : DataFrame ,
295
+ data : DataFrame | _SupportsDataFrame ,
139
296
* ,
140
297
hue : str | None = None ,
141
298
vars : Iterable [str ] | None = None ,
@@ -162,25 +319,25 @@ class JointGrid(_BaseGrid):
162
319
ax_joint : Axes
163
320
ax_marg_x : Axes
164
321
ax_marg_y : Axes
165
- x : Series [Incomplete ]
166
- y : Series [Incomplete ]
167
- hue : Series [Incomplete ]
322
+ x : Series [Any ]
323
+ y : Series [Any ]
324
+ hue : Series [Any ]
168
325
def __init__ (
169
326
self ,
170
- data : Incomplete | None = None ,
327
+ data : DataSource | _DataSourceWideForm | None = None ,
171
328
* ,
172
- x : Incomplete | None = None ,
173
- y : Incomplete | None = None ,
174
- hue : Incomplete | None = None ,
329
+ x : ColumnName | _Vector | None = None ,
330
+ y : ColumnName | _Vector | None = None ,
331
+ hue : ColumnName | _Vector | None = None ,
175
332
height : float = 6 ,
176
333
ratio : float = 5 ,
177
334
space : float = 0.2 ,
178
335
palette : _Palette | Colormap | None = None ,
179
- hue_order : Iterable [str ] | None = None ,
180
- hue_norm : Incomplete | None = None ,
336
+ hue_order : Iterable [ColumnName ] | None = None ,
337
+ hue_norm : tuple [ float , float ] | Normalize | None = None ,
181
338
dropna : bool = False ,
182
- xlim : Incomplete | None = None ,
183
- ylim : Incomplete | None = None ,
339
+ xlim : float | tuple [ float , float ] | None = None ,
340
+ ylim : float | tuple [ float , float ] | None = None ,
184
341
marginal_ticks : bool = False ,
185
342
) -> None : ...
186
343
def plot (self , joint_func : Callable [..., object ], marginal_func : Callable [..., object ], ** kwargs : Any ) -> Self : ...
@@ -194,7 +351,7 @@ class JointGrid(_BaseGrid):
194
351
joint : bool = True ,
195
352
marginal : bool = True ,
196
353
color : ColorType = ".5" ,
197
- linestyle : str = "--" ,
354
+ linestyle : LineStyleType = "--" ,
198
355
** line_kws : Any ,
199
356
) -> Self : ...
200
357
def set_axis_labels (self , xlabel : str = "" , ylabel : str = "" , ** kwargs : Any ) -> Self : ...
@@ -210,7 +367,7 @@ def pairplot(
210
367
y_vars : Iterable [str ] | str | None = None ,
211
368
kind : Literal ["scatter" , "kde" , "hist" , "reg" ] = "scatter" ,
212
369
diag_kind : Literal ["auto" , "hist" , "kde" ] | None = "auto" ,
213
- markers : Incomplete | None = None ,
370
+ markers : MarkerType | list [ MarkerType ] | None = None ,
214
371
height : float = 2.5 ,
215
372
aspect : float = 1 ,
216
373
corner : bool = False ,
@@ -221,22 +378,22 @@ def pairplot(
221
378
size : float | None = None , # deprecated
222
379
) -> PairGrid : ...
223
380
def jointplot (
224
- data : Incomplete | None = None ,
381
+ data : DataSource | _DataSourceWideForm | None = None ,
225
382
* ,
226
- x : Incomplete | None = None ,
227
- y : Incomplete | None = None ,
228
- hue : Incomplete | None = None ,
229
- kind : str = "scatter" , # ideally Literal["scatter", "kde", "hist", "hex", "reg", "resid"] but it is checked with startswith
383
+ x : ColumnName | _Vector | None = None ,
384
+ y : ColumnName | _Vector | None = None ,
385
+ hue : ColumnName | _Vector | None = None ,
386
+ kind : Literal ["scatter" , "kde" , "hist" , "hex" , "reg" , "resid" ] = "scatter" ,
230
387
height : float = 6 ,
231
388
ratio : float = 5 ,
232
389
space : float = 0.2 ,
233
390
dropna : bool = False ,
234
- xlim : Incomplete | None = None ,
235
- ylim : Incomplete | None = None ,
391
+ xlim : float | tuple [ float , float ] | None = None ,
392
+ ylim : float | tuple [ float , float ] | None = None ,
236
393
color : ColorType | None = None ,
237
394
palette : _Palette | Colormap | None = None ,
238
- hue_order : Iterable [str ] | None = None ,
239
- hue_norm : Incomplete | None = None ,
395
+ hue_order : Iterable [ColumnName ] | None = None ,
396
+ hue_norm : tuple [ float , float ] | Normalize | None = None ,
240
397
marginal_ticks : bool = False ,
241
398
joint_kws : dict [str , Any ] | None = None ,
242
399
marginal_kws : dict [str , Any ] | None = None ,
0 commit comments