@@ -152,9 +152,9 @@ def setup(self):
152
152
plt .close ("all" )
153
153
154
154
def pass_in_axis (self , plotmethod , subplot_kw = None ):
155
- fig , axes = plt .subplots (ncols = 2 , subplot_kw = subplot_kw )
156
- plotmethod (ax = axes [0 ])
157
- assert axes [0 ].has_data ()
155
+ fig , axs = plt .subplots (ncols = 2 , subplot_kw = subplot_kw )
156
+ plotmethod (ax = axs [0 ])
157
+ assert axs [0 ].has_data ()
158
158
159
159
@pytest .mark .slow
160
160
def imshow_called (self , plotmethod ):
@@ -602,8 +602,8 @@ def test_convenient_facetgrid(self) -> None:
602
602
d .coords ["z" ] = list ("abcd" )
603
603
g = d .plot (x = "x" , y = "y" , col = "z" , col_wrap = 2 , cmap = "cool" )
604
604
605
- assert_array_equal (g .axes .shape , [2 , 2 ])
606
- for ax in g .axes .flat :
605
+ assert_array_equal (g .axs .shape , [2 , 2 ])
606
+ for ax in g .axs .flat :
607
607
assert ax .has_data ()
608
608
609
609
with pytest .raises (ValueError , match = r"[Ff]acet" ):
@@ -625,7 +625,7 @@ def test_subplot_kws(self) -> None:
625
625
cmap = "cool" ,
626
626
subplot_kws = dict (facecolor = "r" ),
627
627
)
628
- for ax in g .axes .flat :
628
+ for ax in g .axs .flat :
629
629
# mpl V2
630
630
assert ax .get_facecolor ()[0 :3 ] == mpl .colors .to_rgb ("r" )
631
631
@@ -662,8 +662,8 @@ def test_convenient_facetgrid_4d(self) -> None:
662
662
d = DataArray (a , dims = ["y" , "x" , "columns" , "rows" ])
663
663
g = d .plot (x = "x" , y = "y" , col = "columns" , row = "rows" )
664
664
665
- assert_array_equal (g .axes .shape , [3 , 2 ])
666
- for ax in g .axes .flat :
665
+ assert_array_equal (g .axs .shape , [3 , 2 ])
666
+ for ax in g .axs .flat :
667
667
assert ax .has_data ()
668
668
669
669
with pytest .raises (ValueError , match = r"[Ff]acet" ):
@@ -1529,7 +1529,7 @@ def test_verbose_facetgrid(self) -> None:
1529
1529
d = DataArray (a , dims = ["y" , "x" , "z" ])
1530
1530
g = xplt .FacetGrid (d , col = "z" , subplot_kws = self .subplot_kws )
1531
1531
g .map_dataarray (self .plotfunc , "x" , "y" )
1532
- for ax in g .axes .flat :
1532
+ for ax in g .axs .flat :
1533
1533
assert ax .has_data ()
1534
1534
1535
1535
def test_2d_function_and_method_signature_same (self ) -> None :
@@ -1544,8 +1544,8 @@ def test_convenient_facetgrid(self) -> None:
1544
1544
d = DataArray (a , dims = ["y" , "x" , "z" ])
1545
1545
g = self .plotfunc (d , x = "x" , y = "y" , col = "z" , col_wrap = 2 )
1546
1546
1547
- assert_array_equal (g .axes .shape , [2 , 2 ])
1548
- for (y , x ), ax in np .ndenumerate (g .axes ):
1547
+ assert_array_equal (g .axs .shape , [2 , 2 ])
1548
+ for (y , x ), ax in np .ndenumerate (g .axs ):
1549
1549
assert ax .has_data ()
1550
1550
if x == 0 :
1551
1551
assert "y" == ax .get_ylabel ()
@@ -1558,8 +1558,8 @@ def test_convenient_facetgrid(self) -> None:
1558
1558
1559
1559
# Inferring labels
1560
1560
g = self .plotfunc (d , col = "z" , col_wrap = 2 )
1561
- assert_array_equal (g .axes .shape , [2 , 2 ])
1562
- for (y , x ), ax in np .ndenumerate (g .axes ):
1561
+ assert_array_equal (g .axs .shape , [2 , 2 ])
1562
+ for (y , x ), ax in np .ndenumerate (g .axs ):
1563
1563
assert ax .has_data ()
1564
1564
if x == 0 :
1565
1565
assert "y" == ax .get_ylabel ()
@@ -1576,8 +1576,8 @@ def test_convenient_facetgrid_4d(self) -> None:
1576
1576
d = DataArray (a , dims = ["y" , "x" , "columns" , "rows" ])
1577
1577
g = self .plotfunc (d , x = "x" , y = "y" , col = "columns" , row = "rows" )
1578
1578
1579
- assert_array_equal (g .axes .shape , [3 , 2 ])
1580
- for ax in g .axes .flat :
1579
+ assert_array_equal (g .axs .shape , [3 , 2 ])
1580
+ for ax in g .axs .flat :
1581
1581
assert ax .has_data ()
1582
1582
1583
1583
@pytest .mark .filterwarnings ("ignore:This figure includes" )
@@ -2035,16 +2035,16 @@ def test_convenient_facetgrid(self) -> None:
2035
2035
d = DataArray (a , dims = ["y" , "x" , "z" ])
2036
2036
g = self .plotfunc (d , x = "x" , y = "y" , col = "z" , col_wrap = 2 )
2037
2037
2038
- assert_array_equal (g .axes .shape , [2 , 2 ])
2039
- for (y , x ), ax in np .ndenumerate (g .axes ):
2038
+ assert_array_equal (g .axs .shape , [2 , 2 ])
2039
+ for (y , x ), ax in np .ndenumerate (g .axs ):
2040
2040
assert ax .has_data ()
2041
2041
assert "y" == ax .get_ylabel ()
2042
2042
assert "x" == ax .get_xlabel ()
2043
2043
2044
2044
# Inferring labels
2045
2045
g = self .plotfunc (d , col = "z" , col_wrap = 2 )
2046
- assert_array_equal (g .axes .shape , [2 , 2 ])
2047
- for (y , x ), ax in np .ndenumerate (g .axes ):
2046
+ assert_array_equal (g .axs .shape , [2 , 2 ])
2047
+ for (y , x ), ax in np .ndenumerate (g .axs ):
2048
2048
assert ax .has_data ()
2049
2049
assert "y" == ax .get_ylabel ()
2050
2050
assert "x" == ax .get_xlabel ()
@@ -2077,14 +2077,14 @@ def test_no_args(self) -> None:
2077
2077
alltxt = text_in_fig ()
2078
2078
assert "None" not in alltxt
2079
2079
2080
- for ax in self .g .axes .flat :
2080
+ for ax in self .g .axs .flat :
2081
2081
assert ax .has_data ()
2082
2082
2083
2083
@pytest .mark .slow
2084
2084
def test_names_appear_somewhere (self ) -> None :
2085
2085
self .darray .name = "testvar"
2086
2086
self .g .map_dataarray (xplt .contourf , "x" , "y" )
2087
- for k , ax in zip ("abc" , self .g .axes .flat ):
2087
+ for k , ax in zip ("abc" , self .g .axs .flat ):
2088
2088
assert f"z = { k } " == ax .get_title ()
2089
2089
2090
2090
alltxt = text_in_fig ()
@@ -2101,7 +2101,7 @@ def test_text_not_super_long(self) -> None:
2101
2101
maxlen = max (len (txt ) for txt in alltxt )
2102
2102
assert maxlen < 50
2103
2103
2104
- t0 = g .axes [0 , 0 ].get_title ()
2104
+ t0 = g .axs [0 , 0 ].get_title ()
2105
2105
assert t0 .endswith ("..." )
2106
2106
2107
2107
@pytest .mark .slow
@@ -2123,7 +2123,7 @@ def test_empty_cell(self) -> None:
2123
2123
g = xplt .FacetGrid (self .darray , col = "z" , col_wrap = 2 )
2124
2124
g .map_dataarray (xplt .imshow , "x" , "y" )
2125
2125
2126
- bottomright = g .axes [- 1 , - 1 ]
2126
+ bottomright = g .axs [- 1 , - 1 ]
2127
2127
assert not bottomright .has_data ()
2128
2128
assert not bottomright .get_visible ()
2129
2129
@@ -2230,7 +2230,7 @@ def test_num_ticks(self) -> None:
2230
2230
self .g .map_dataarray (xplt .imshow , "x" , "y" )
2231
2231
self .g .set_ticks (max_xticks = nticks , max_yticks = nticks )
2232
2232
2233
- for ax in self .g .axes .flat :
2233
+ for ax in self .g .axs .flat :
2234
2234
xticks = len (ax .get_xticks ())
2235
2235
yticks = len (ax .get_yticks ())
2236
2236
assert xticks <= maxticks
@@ -2314,36 +2314,36 @@ def test_title_kwargs(self) -> None:
2314
2314
g .set_titles (template = "{value}" , weight = "bold" )
2315
2315
2316
2316
# Rightmost column titles should be bold
2317
- for label , ax in zip (self .darray .coords ["row" ].values , g .axes [:, - 1 ]):
2317
+ for label , ax in zip (self .darray .coords ["row" ].values , g .axs [:, - 1 ]):
2318
2318
assert property_in_axes_text ("weight" , "bold" , label , ax )
2319
2319
2320
2320
# Top row titles should be bold
2321
- for label , ax in zip (self .darray .coords ["col" ].values , g .axes [0 , :]):
2321
+ for label , ax in zip (self .darray .coords ["col" ].values , g .axs [0 , :]):
2322
2322
assert property_in_axes_text ("weight" , "bold" , label , ax )
2323
2323
2324
2324
@pytest .mark .slow
2325
2325
def test_default_labels (self ) -> None :
2326
2326
g = xplt .FacetGrid (self .darray , col = "col" , row = "row" )
2327
- assert (2 , 3 ) == g .axes .shape
2327
+ assert (2 , 3 ) == g .axs .shape
2328
2328
2329
2329
g .map_dataarray (xplt .imshow , "x" , "y" )
2330
2330
2331
2331
# Rightmost column should be labeled
2332
- for label , ax in zip (self .darray .coords ["row" ].values , g .axes [:, - 1 ]):
2332
+ for label , ax in zip (self .darray .coords ["row" ].values , g .axs [:, - 1 ]):
2333
2333
assert substring_in_axes (label , ax )
2334
2334
2335
2335
# Top row should be labeled
2336
- for label , ax in zip (self .darray .coords ["col" ].values , g .axes [0 , :]):
2336
+ for label , ax in zip (self .darray .coords ["col" ].values , g .axs [0 , :]):
2337
2337
assert substring_in_axes (label , ax )
2338
2338
2339
2339
# ensure that row & col labels can be changed
2340
2340
g .set_titles ("abc={value}" )
2341
- for label , ax in zip (self .darray .coords ["row" ].values , g .axes [:, - 1 ]):
2341
+ for label , ax in zip (self .darray .coords ["row" ].values , g .axs [:, - 1 ]):
2342
2342
assert substring_in_axes (f"abc={ label } " , ax )
2343
2343
# previous labels were "row=row0" etc.
2344
2344
assert substring_not_in_axes ("row=" , ax )
2345
2345
2346
- for label , ax in zip (self .darray .coords ["col" ].values , g .axes [0 , :]):
2346
+ for label , ax in zip (self .darray .coords ["col" ].values , g .axs [0 , :]):
2347
2347
assert substring_in_axes (f"abc={ label } " , ax )
2348
2348
# previous labels were "col=row0" etc.
2349
2349
assert substring_not_in_axes ("col=" , ax )
@@ -2381,15 +2381,15 @@ def setUp(self) -> None:
2381
2381
2382
2382
def test_facetgrid_shape (self ) -> None :
2383
2383
g = self .darray .plot (row = "row" , col = "col" , hue = "hue" )
2384
- assert g .axes .shape == (len (self .darray .row ), len (self .darray .col ))
2384
+ assert g .axs .shape == (len (self .darray .row ), len (self .darray .col ))
2385
2385
2386
2386
g = self .darray .plot (row = "col" , col = "row" , hue = "hue" )
2387
- assert g .axes .shape == (len (self .darray .col ), len (self .darray .row ))
2387
+ assert g .axs .shape == (len (self .darray .col ), len (self .darray .row ))
2388
2388
2389
2389
def test_unnamed_args (self ) -> None :
2390
2390
g = self .darray .plot .line ("o--" , row = "row" , col = "col" , hue = "hue" )
2391
2391
lines = [
2392
- q for q in g .axes .flat [0 ].get_children () if isinstance (q , mpl .lines .Line2D )
2392
+ q for q in g .axs .flat [0 ].get_children () if isinstance (q , mpl .lines .Line2D )
2393
2393
]
2394
2394
# passing 'o--' as argument should set marker and linestyle
2395
2395
assert lines [0 ].get_marker () == "o"
@@ -2398,15 +2398,15 @@ def test_unnamed_args(self) -> None:
2398
2398
def test_default_labels (self ) -> None :
2399
2399
g = self .darray .plot (row = "row" , col = "col" , hue = "hue" )
2400
2400
# Rightmost column should be labeled
2401
- for label , ax in zip (self .darray .coords ["row" ].values , g .axes [:, - 1 ]):
2401
+ for label , ax in zip (self .darray .coords ["row" ].values , g .axs [:, - 1 ]):
2402
2402
assert substring_in_axes (label , ax )
2403
2403
2404
2404
# Top row should be labeled
2405
- for label , ax in zip (self .darray .coords ["col" ].values , g .axes [0 , :]):
2405
+ for label , ax in zip (self .darray .coords ["col" ].values , g .axs [0 , :]):
2406
2406
assert substring_in_axes (str (label ), ax )
2407
2407
2408
2408
# Leftmost column should have array name
2409
- for ax in g .axes [:, 0 ]:
2409
+ for ax in g .axs [:, 0 ]:
2410
2410
assert substring_in_axes (self .darray .name , ax )
2411
2411
2412
2412
def test_test_empty_cell (self ) -> None :
@@ -2415,7 +2415,7 @@ def test_test_empty_cell(self) -> None:
2415
2415
.drop_vars ("row" )
2416
2416
.plot (col = "col" , hue = "hue" , col_wrap = 2 )
2417
2417
)
2418
- bottomright = g .axes [- 1 , - 1 ]
2418
+ bottomright = g .axs [- 1 , - 1 ]
2419
2419
assert not bottomright .has_data ()
2420
2420
assert not bottomright .get_visible ()
2421
2421
@@ -2641,24 +2641,24 @@ def test_add_guide(
2641
2641
2642
2642
def test_facetgrid_shape (self ) -> None :
2643
2643
g = self .ds .plot .scatter (x = "A" , y = "B" , row = "row" , col = "col" )
2644
- assert g .axes .shape == (len (self .ds .row ), len (self .ds .col ))
2644
+ assert g .axs .shape == (len (self .ds .row ), len (self .ds .col ))
2645
2645
2646
2646
g = self .ds .plot .scatter (x = "A" , y = "B" , row = "col" , col = "row" )
2647
- assert g .axes .shape == (len (self .ds .col ), len (self .ds .row ))
2647
+ assert g .axs .shape == (len (self .ds .col ), len (self .ds .row ))
2648
2648
2649
2649
def test_default_labels (self ) -> None :
2650
2650
g = self .ds .plot .scatter (x = "A" , y = "B" , row = "row" , col = "col" , hue = "hue" )
2651
2651
2652
2652
# Top row should be labeled
2653
- for label , ax in zip (self .ds .coords ["col" ].values , g .axes [0 , :]):
2653
+ for label , ax in zip (self .ds .coords ["col" ].values , g .axs [0 , :]):
2654
2654
assert substring_in_axes (str (label ), ax )
2655
2655
2656
2656
# Bottom row should have name of x array name and units
2657
- for ax in g .axes [- 1 , :]:
2657
+ for ax in g .axs [- 1 , :]:
2658
2658
assert ax .get_xlabel () == "A [Aunits]"
2659
2659
2660
2660
# Leftmost column should have name of y array name and units
2661
- for ax in g .axes [:, 0 ]:
2661
+ for ax in g .axs [:, 0 ]:
2662
2662
assert ax .get_ylabel () == "B [Bunits]"
2663
2663
2664
2664
def test_axes_in_faceted_plot (self ) -> None :
@@ -3178,3 +3178,18 @@ def test_assert_valid_xy() -> None:
3178
3178
# A hashable that is not valid should error:
3179
3179
with pytest .raises (ValueError , match = "x must be one of" ):
3180
3180
_assert_valid_xy (darray = darray , xy = "error_now" , name = "x" )
3181
+
3182
+
3183
+ @requires_matplotlib
3184
+ def test_facetgrid_axes_raises_deprecation_warning ():
3185
+ with pytest .warns (
3186
+ DeprecationWarning ,
3187
+ match = (
3188
+ "self.axes is deprecated since 2022.11 in order to align with "
3189
+ "matplotlibs plt.subplots, use self.axs instead."
3190
+ ),
3191
+ ):
3192
+ with figure_context ():
3193
+ ds = xr .tutorial .scatter_example_dataset ()
3194
+ g = ds .plot .scatter (x = "A" , y = "B" , col = "x" )
3195
+ g .axes
0 commit comments