1212
1313from matplotlib import cbook , cm , cycler
1414import matplotlib
15+ import matplotlib as mpl
1516import matplotlib .colors as mcolors
1617import matplotlib .colorbar as mcolorbar
1718import matplotlib .pyplot as plt
@@ -29,9 +30,9 @@ def test_create_lookup_table(N, result):
2930 assert_array_almost_equal (mcolors ._create_lookup_table (N , data ), result )
3031
3132
32- def test_resample ():
33+ def test_resampled ():
3334 """
34- GitHub issue #6025 pointed to incorrect ListedColormap.resample ;
35+ GitHub issue #6025 pointed to incorrect ListedColormap.resampled ;
3536 here we test the method for LinearSegmentedColormap as well.
3637 """
3738 n = 101
@@ -47,8 +48,8 @@ def test_resample():
4748 cmap .set_under ('r' )
4849 cmap .set_over ('g' )
4950 cmap .set_bad ('b' )
50- lsc3 = lsc .resample (3 )
51- lc3 = lc .resample (3 )
51+ lsc3 = lsc .resampled (3 )
52+ lc3 = lc .resampled (3 )
5253 expected = np .array ([[0.0 , 0.2 , 1.0 , 0.7 ],
5354 [0.5 , 0.2 , 0.5 , 0.7 ],
5455 [1.0 , 0.2 , 0.0 , 0.7 ]], float )
@@ -127,7 +128,7 @@ def test_colormap_copy():
127128
128129
129130def test_colormap_equals ():
130- cmap = plt . get_cmap ( "plasma" )
131+ cmap = mpl . colormaps [ "plasma" ]
131132 cm_copy = cmap .copy ()
132133 # different object id's
133134 assert cm_copy is not cmap
@@ -155,7 +156,7 @@ def test_colormap_endian():
155156 mapping of 1.0 when input from a non-native-byteorder
156157 array.
157158 """
158- cmap = cm . get_cmap ( "jet" )
159+ cmap = mpl . colormaps [ "jet" ]
159160 # Test under, over, and invalid along with values 0 and 1.
160161 a = [- 0.5 , 0 , 0.5 , 1 , 1.5 , np .nan ]
161162 for dt in ["f2" , "f4" , "f8" ]:
@@ -170,7 +171,7 @@ def test_colormap_invalid():
170171 rather than bad. This tests to make sure all invalid values
171172 (-inf, nan, inf) are mapped respectively to (under, bad, over).
172173 """
173- cmap = cm . get_cmap ( "plasma" )
174+ cmap = mpl . colormaps [ "plasma" ]
174175 x = np .array ([- np .inf , - 1 , 0 , np .nan , .7 , 2 , np .inf ])
175176
176177 expected = np .array ([[0.050383 , 0.029803 , 0.527975 , 1. ],
@@ -203,7 +204,7 @@ def test_colormap_return_types():
203204 Make sure that tuples are returned for scalar input and
204205 that the proper shapes are returned for ndarrays.
205206 """
206- cmap = cm . get_cmap ( "plasma" )
207+ cmap = mpl . colormaps [ "plasma" ]
207208 # Test return types and shapes
208209 # scalar input needs to return a tuple of length 4
209210 assert isinstance (cmap (0.5 ), tuple )
@@ -318,7 +319,7 @@ def test_BoundaryNorm():
318319
319320 # Testing extend keyword, with interpolation (large cmap)
320321 bounds = [1 , 2 , 3 ]
321- cmap = cm . get_cmap ( 'viridis' )
322+ cmap = mpl . colormaps [ 'viridis' ]
322323 mynorm = mcolors .BoundaryNorm (bounds , cmap .N , extend = 'both' )
323324 refnorm = mcolors .BoundaryNorm ([0 ] + bounds + [4 ], cmap .N )
324325 x = np .random .randn (100 ) * 10 + 2
@@ -789,7 +790,7 @@ def test_boundarynorm_and_colorbarbase():
789790
790791 # Set the colormap and bounds
791792 bounds = [- 1 , 2 , 5 , 7 , 12 , 15 ]
792- cmap = cm . get_cmap ( 'viridis' )
793+ cmap = mpl . colormaps [ 'viridis' ]
793794
794795 # Default behavior
795796 norm = mcolors .BoundaryNorm (bounds , cmap .N )
@@ -1134,13 +1135,13 @@ def test_pandas_iterable(pd):
11341135 assert_array_equal (cm1 .colors , cm2 .colors )
11351136
11361137
1137- @pytest .mark .parametrize ('name' , sorted (plt .colormaps ()))
1138+ @pytest .mark .parametrize ('name' , sorted (mpl .colormaps ()))
11381139def test_colormap_reversing (name ):
11391140 """
11401141 Check the generated _lut data of a colormap and corresponding reversed
11411142 colormap if they are almost the same.
11421143 """
1143- cmap = plt . get_cmap ( name )
1144+ cmap = mpl . colormaps [ name ]
11441145 cmap_r = cmap .reversed ()
11451146 if not cmap_r ._isinit :
11461147 cmap ._init ()
@@ -1307,7 +1308,7 @@ def test_hex_shorthand_notation():
13071308
13081309
13091310def test_repr_png ():
1310- cmap = plt . get_cmap ( 'viridis' )
1311+ cmap = mpl . colormaps [ 'viridis' ]
13111312 png = cmap ._repr_png_ ()
13121313 assert len (png ) > 0
13131314 img = Image .open (BytesIO (png ))
@@ -1320,7 +1321,7 @@ def test_repr_png():
13201321
13211322
13221323def test_repr_html ():
1323- cmap = plt . get_cmap ( 'viridis' )
1324+ cmap = mpl . colormaps [ 'viridis' ]
13241325 html = cmap ._repr_html_ ()
13251326 assert len (html ) > 0
13261327 png = cmap ._repr_png_ ()
@@ -1331,15 +1332,15 @@ def test_repr_html():
13311332
13321333
13331334def test_get_under_over_bad ():
1334- cmap = plt . get_cmap ( 'viridis' )
1335+ cmap = mpl . colormaps [ 'viridis' ]
13351336 assert_array_equal (cmap .get_under (), cmap (- np .inf ))
13361337 assert_array_equal (cmap .get_over (), cmap (np .inf ))
13371338 assert_array_equal (cmap .get_bad (), cmap (np .nan ))
13381339
13391340
13401341@pytest .mark .parametrize ('kind' , ('over' , 'under' , 'bad' ))
13411342def test_non_mutable_get_values (kind ):
1342- cmap = copy .copy (plt . get_cmap ( 'viridis' ) )
1343+ cmap = copy .copy (mpl . colormaps [ 'viridis' ] )
13431344 init_value = getattr (cmap , f'get_{ kind } ' )()
13441345 getattr (cmap , f'set_{ kind } ' )('k' )
13451346 black_value = getattr (cmap , f'get_{ kind } ' )()
@@ -1348,7 +1349,7 @@ def test_non_mutable_get_values(kind):
13481349
13491350
13501351def test_colormap_alpha_array ():
1351- cmap = plt . get_cmap ( 'viridis' )
1352+ cmap = mpl . colormaps [ 'viridis' ]
13521353 vals = [- 1 , 0.5 , 2 ] # under, valid, over
13531354 with pytest .raises (ValueError , match = "alpha is array-like but" ):
13541355 cmap (vals , alpha = [1 , 1 , 1 , 1 ])
@@ -1360,7 +1361,7 @@ def test_colormap_alpha_array():
13601361
13611362
13621363def test_colormap_bad_data_with_alpha ():
1363- cmap = plt . get_cmap ( 'viridis' )
1364+ cmap = mpl . colormaps [ 'viridis' ]
13641365 c = cmap (np .nan , alpha = 0.5 )
13651366 assert c == (0 , 0 , 0 , 0 )
13661367 c = cmap ([0.5 , np .nan ], alpha = 0.5 )
0 commit comments