@@ -94,7 +94,7 @@ class FacetGrid(Generic[T_Xarray]):
94
94
95
95
Attributes
96
96
----------
97
- axes : ndarray of matplotlib.axes.Axes
97
+ axs : ndarray of matplotlib.axes.Axes
98
98
Array containing axes in corresponding position, as returned from
99
99
:py:func:`matplotlib.pyplot.subplots`.
100
100
col_labels : list of matplotlib.text.Annotation
@@ -112,7 +112,7 @@ class FacetGrid(Generic[T_Xarray]):
112
112
data : T_Xarray
113
113
name_dicts : np .ndarray
114
114
fig : Figure
115
- axes : np .ndarray
115
+ axs : np .ndarray
116
116
row_names : list [np .ndarray ]
117
117
col_names : list [np .ndarray ]
118
118
figlegend : Legend | None
@@ -223,7 +223,7 @@ def __init__(
223
223
cbar_space = 1
224
224
figsize = (ncol * size * aspect + cbar_space , nrow * size )
225
225
226
- fig , axes = plt .subplots (
226
+ fig , axs = plt .subplots (
227
227
nrow ,
228
228
ncol ,
229
229
sharex = sharex ,
@@ -258,7 +258,7 @@ def __init__(
258
258
self .data = data
259
259
self .name_dicts = name_dicts
260
260
self .fig = fig
261
- self .axes = axes
261
+ self .axs = axs
262
262
self .row_names = row_names
263
263
self .col_names = col_names
264
264
@@ -282,13 +282,37 @@ def __init__(
282
282
self ._mappables = []
283
283
self ._finalized = False
284
284
285
+ @property
286
+ def axes (self ) -> np .ndarray :
287
+ warnings .warn (
288
+ (
289
+ "self.axes is deprecated since 2022.11 in order to align with "
290
+ "matplotlibs plt.subplots, use self.axs instead."
291
+ ),
292
+ DeprecationWarning ,
293
+ stacklevel = 2 ,
294
+ )
295
+ return self .axs
296
+
297
+ @axes .setter
298
+ def axes (self , axs : np .ndarray ) -> None :
299
+ warnings .warn (
300
+ (
301
+ "self.axes is deprecated since 2022.11 in order to align with "
302
+ "matplotlibs plt.subplots, use self.axs instead."
303
+ ),
304
+ DeprecationWarning ,
305
+ stacklevel = 2 ,
306
+ )
307
+ self .axs = axs
308
+
285
309
@property
286
310
def _left_axes (self ) -> np .ndarray :
287
- return self .axes [:, 0 ]
311
+ return self .axs [:, 0 ]
288
312
289
313
@property
290
314
def _bottom_axes (self ) -> np .ndarray :
291
- return self .axes [- 1 , :]
315
+ return self .axs [- 1 , :]
292
316
293
317
def map_dataarray (
294
318
self : T_FacetGrid ,
@@ -347,7 +371,7 @@ def map_dataarray(
347
371
rgb = kwargs .get ("rgb" , None ),
348
372
)
349
373
350
- for d , ax in zip (self .name_dicts .flat , self .axes .flat ):
374
+ for d , ax in zip (self .name_dicts .flat , self .axs .flat ):
351
375
# None is the sentinel value
352
376
if d is not None :
353
377
subset = self .data .loc [d ]
@@ -449,7 +473,7 @@ def map_plot1d(
449
473
func_kwargs ["add_legend" ] = False
450
474
func_kwargs ["add_title" ] = False
451
475
452
- add_labels_ = np .zeros (self .axes .shape + (3 ,), dtype = bool )
476
+ add_labels_ = np .zeros (self .axs .shape + (3 ,), dtype = bool )
453
477
if kwargs .get ("z" ) is not None :
454
478
# 3d plots looks better with all labels. 3d plots can't sharex either so it
455
479
# is easy to get lost while rotating the plots:
@@ -478,7 +502,7 @@ def map_plot1d(
478
502
479
503
# Plot the data for each subplot:
480
504
for add_lbls , d , ax in zip (
481
- add_labels_ .reshape ((self .axes .size , - 1 )), name_dicts .flat , self .axes .flat
505
+ add_labels_ .reshape ((self .axs .size , - 1 )), name_dicts .flat , self .axs .flat
482
506
):
483
507
func_kwargs ["add_labels" ] = add_lbls
484
508
# None is the sentinel value
@@ -542,7 +566,7 @@ def map_dataarray_line(
542
566
) -> T_FacetGrid :
543
567
from .dataarray_plot import _infer_line_data
544
568
545
- for d , ax in zip (self .name_dicts .flat , self .axes .flat ):
569
+ for d , ax in zip (self .name_dicts .flat , self .axs .flat ):
546
570
# None is the sentinel value
547
571
if d is not None :
548
572
subset = self .data .loc [d ]
@@ -609,7 +633,7 @@ def map_dataset(
609
633
raise ValueError ("Please provide scale." )
610
634
# TODO: come up with an algorithm for reasonable scale choice
611
635
612
- for d , ax in zip (self .name_dicts .flat , self .axes .flat ):
636
+ for d , ax in zip (self .name_dicts .flat , self .axs .flat ):
613
637
# None is the sentinel value
614
638
if d is not None :
615
639
subset = self .data .loc [d ]
@@ -643,7 +667,7 @@ def _finalize_grid(self, *axlabels: Hashable) -> None:
643
667
self .set_titles ()
644
668
self .fig .tight_layout ()
645
669
646
- for ax , namedict in zip (self .axes .flat , self .name_dicts .flat ):
670
+ for ax , namedict in zip (self .axs .flat , self .name_dicts .flat ):
647
671
if namedict is None :
648
672
ax .set_visible (False )
649
673
@@ -703,15 +727,15 @@ def add_colorbar(self, **kwargs: Any) -> None:
703
727
if "label" not in kwargs :
704
728
kwargs .setdefault ("label" , label_from_attrs (self .data ))
705
729
self .cbar = self .fig .colorbar (
706
- self ._mappables [- 1 ], ax = list (self .axes .flat ), ** kwargs
730
+ self ._mappables [- 1 ], ax = list (self .axs .flat ), ** kwargs
707
731
)
708
732
709
733
def add_quiverkey (self , u : Hashable , v : Hashable , ** kwargs : Any ) -> None :
710
734
kwargs = kwargs .copy ()
711
735
712
736
magnitude = _get_nice_quiver_magnitude (self .data [u ], self .data [v ])
713
737
units = self .data [u ].attrs .get ("units" , "" )
714
- self .quiverkey = self .axes .flat [- 1 ].quiverkey (
738
+ self .quiverkey = self .axs .flat [- 1 ].quiverkey (
715
739
self ._mappables [- 1 ],
716
740
X = 0.8 ,
717
741
Y = 0.9 ,
@@ -747,7 +771,7 @@ def _get_largest_lims(self) -> dict[str, tuple[float, float]]:
747
771
for axis in ("x" , "y" , "z" ):
748
772
# Find the plot with the largest xlim values:
749
773
lower , upper = lims_largest [axis ]
750
- for ax in self .axes .flat :
774
+ for ax in self .axs .flat :
751
775
get_lim : None | Callable [[], tuple [float , float ]] = getattr (
752
776
ax , f"get_{ axis } lim" , None
753
777
)
@@ -781,13 +805,13 @@ def _set_lims(
781
805
>>> ds = xr.tutorial.scatter_example_dataset(seed=42)
782
806
>>> fg = ds.plot.scatter(x="A", y="B", hue="y", row="x", col="w")
783
807
>>> fg._set_lims(x=(-0.3, 0.3), y=(0, 2), z=(0, 4))
784
- >>> fg.axes [0, 0].get_xlim(), fg.axes [0, 0].get_ylim()
808
+ >>> fg.axs [0, 0].get_xlim(), fg.axs [0, 0].get_ylim()
785
809
((-0.3, 0.3), (0.0, 2.0))
786
810
"""
787
811
lims_largest = self ._get_largest_lims ()
788
812
789
813
# Set limits:
790
- for ax in self .axes .flat :
814
+ for ax in self .axs .flat :
791
815
for (axis , data_limit ), parameter_limit in zip (
792
816
lims_largest .items (), (x , y , z )
793
817
):
@@ -858,7 +882,7 @@ def set_titles(
858
882
nicetitle = functools .partial (_nicetitle , maxchar = maxchar , template = template )
859
883
860
884
if self ._single_group :
861
- for d , ax in zip (self .name_dicts .flat , self .axes .flat ):
885
+ for d , ax in zip (self .name_dicts .flat , self .axs .flat ):
862
886
# Only label the ones with data
863
887
if d is not None :
864
888
coord , value = list (d .items ()).pop ()
@@ -867,7 +891,7 @@ def set_titles(
867
891
else :
868
892
# The row titles on the right edge of the grid
869
893
for index , (ax , row_name , handle ) in enumerate (
870
- zip (self .axes [:, - 1 ], self .row_names , self .row_labels )
894
+ zip (self .axs [:, - 1 ], self .row_names , self .row_labels )
871
895
):
872
896
title = nicetitle (coord = self ._row_var , value = row_name , maxchar = maxchar )
873
897
if not handle :
@@ -886,7 +910,7 @@ def set_titles(
886
910
887
911
# The column titles on the top row
888
912
for index , (ax , col_name , handle ) in enumerate (
889
- zip (self .axes [0 , :], self .col_names , self .col_labels )
913
+ zip (self .axs [0 , :], self .col_names , self .col_labels )
890
914
):
891
915
title = nicetitle (coord = self ._col_var , value = col_name , maxchar = maxchar )
892
916
if not handle :
@@ -922,7 +946,7 @@ def set_ticks(
922
946
x_major_locator = MaxNLocator (nbins = max_xticks )
923
947
y_major_locator = MaxNLocator (nbins = max_yticks )
924
948
925
- for ax in self .axes .flat :
949
+ for ax in self .axs .flat :
926
950
ax .xaxis .set_major_locator (x_major_locator )
927
951
ax .yaxis .set_major_locator (y_major_locator )
928
952
for tick in itertools .chain (
@@ -957,7 +981,7 @@ def map(
957
981
"""
958
982
plt = import_matplotlib_pyplot ()
959
983
960
- for ax , namedict in zip (self .axes .flat , self .name_dicts .flat ):
984
+ for ax , namedict in zip (self .axs .flat , self .name_dicts .flat ):
961
985
if namedict is not None :
962
986
data = self .data .loc [namedict ]
963
987
plt .sca (ax )
0 commit comments