1010from . import assert_no_warnings , subplots_context
1111
1212MPL_GE_310 = Version (Version (mpl .__version__ ).base_version ) >= Version ("3.10" )
13+ MPL_GE_311 = Version (Version (mpl .__version__ ).base_version ) >= Version ("3.11" )
1314requires_mpl_ge_310 = pytest .mark .skipif (not MPL_GE_310 , reason = "requires mpl >= 3.10" )
1415
1516
2021)
2122
2223
24+ def get_hatchcolor (h ):
25+ if MPL_GE_311 :
26+ return mpl .colors .to_rgba (h .get_hatchcolor ())
27+
28+ return h ._hatch_color
29+
30+
2331@pytest .mark .parametrize ("obj" , (None , xr .Dataset (), np .array ([])))
2432@pytest .mark .parametrize ("function" , HATCH_FUNCTIONS )
2533def test_hatch_not_a_dataarray (obj , function ):
@@ -91,7 +99,7 @@ def test_hatch_label(function):
9199 (rect ,) = h
92100
93101 assert rect .get_label () == "label"
94- assert mpl .colors .to_rgba ("0.1" ) == rect . _hatch_color
102+ assert mpl .colors .to_rgba ("0.1" ) == get_hatchcolor ( rect )
95103
96104 # test 2 labels with non-default color
97105 with subplots_context (1 , 1 , subplot_kw = subplot_kw ) as (__ , ax ):
@@ -106,7 +114,7 @@ def test_hatch_label(function):
106114
107115 for i , rect in enumerate (h ):
108116 assert rect .get_label () == f"label{ i } "
109- assert mpl .colors .to_rgba ("#2ca25f" ) == rect . _hatch_color
117+ assert mpl .colors .to_rgba ("#2ca25f" ) == get_hatchcolor ( rect )
110118
111119
112120@pytest .mark .skipif (MPL_GE_310 , reason = "only for mpl < 3.10" )
@@ -215,16 +223,16 @@ def test_hatch_color(function):
215223 with subplots_context (1 , 1 , subplot_kw = subplot_kw ) as (__ , ax ):
216224 h = function (da , "*" , ax = ax )
217225
218- assert mpl .colors .to_rgba ("0.1" ) == h . _hatch_color
226+ assert mpl .colors .to_rgba ("0.1" ) == get_hatchcolor ( h )
219227
220228 # different colors can be set
221229 with subplots_context (1 , 1 , subplot_kw = subplot_kw ) as (__ , ax ):
222230
223231 h = function (da , "*" , ax = ax , color = "#2ca25f" )
224- assert mpl .colors .to_rgba ("#2ca25f" ) == h . _hatch_color
232+ assert mpl .colors .to_rgba ("#2ca25f" ) == get_hatchcolor ( h )
225233
226234 h = function (da , "*" , ax = ax , color = "#e5f5f9" )
227- assert mpl .colors .to_rgba ("#e5f5f9" ) == h . _hatch_color
235+ assert mpl .colors .to_rgba ("#e5f5f9" ) == get_hatchcolor ( h )
228236
229237
230238def test_hatch_bbox ():
0 commit comments