@@ -221,6 +221,96 @@ def test_Normalize():
221
221
assert 0 < norm (1 + 50 * eps ) < 1
222
222
223
223
224
+ def test_DivergingNorm_autoscale ():
225
+ norm = mcolors .DivergingNorm (vcenter = 20 )
226
+ norm .autoscale ([10 , 20 , 30 , 40 ])
227
+ assert norm .vmin == 10.
228
+ assert norm .vmax == 40.
229
+
230
+
231
+ def test_DivergingNorm_autoscale_None_vmin ():
232
+ norm = mcolors .DivergingNorm (2 , vmin = 0 , vmax = None )
233
+ norm .autoscale_None ([1 , 2 , 3 , 4 , 5 ])
234
+ assert norm (5 ) == 1
235
+ assert norm .vmax == 5
236
+
237
+
238
+ def test_DivergingNorm_autoscale_None_vmax ():
239
+ norm = mcolors .DivergingNorm (2 , vmin = None , vmax = 10 )
240
+ norm .autoscale_None ([1 , 2 , 3 , 4 , 5 ])
241
+ assert norm (1 ) == 0
242
+ assert norm .vmin == 1
243
+
244
+
245
+ def test_DivergingNorm_scale ():
246
+ norm = mcolors .DivergingNorm (2 )
247
+ assert norm .scaled () is False
248
+ norm ([1 , 2 , 3 , 4 ])
249
+ assert norm .scaled () is True
250
+
251
+
252
+ def test_DivergingNorm_scaleout_center ():
253
+ # test the vmin never goes above vcenter
254
+ norm = mcolors .DivergingNorm (vcenter = 0 )
255
+ x = norm ([1 , 2 , 3 , 5 ])
256
+ assert norm .vmin == 0
257
+ assert norm .vmax == 5
258
+
259
+
260
+ def test_DivergingNorm_scaleout_center_max ():
261
+ # test the vmax never goes below vcenter
262
+ norm = mcolors .DivergingNorm (vcenter = 0 )
263
+ x = norm ([- 1 , - 2 , - 3 , - 5 ])
264
+ assert norm .vmax == 0
265
+ assert norm .vmin == - 5
266
+
267
+
268
+ def test_DivergingNorm_Even ():
269
+ norm = mcolors .DivergingNorm (vmin = - 1 , vcenter = 0 , vmax = 4 )
270
+ vals = np .array ([- 1.0 , - 0.5 , 0.0 , 1.0 , 2.0 , 3.0 , 4.0 ])
271
+ expected = np .array ([0.0 , 0.25 , 0.5 , 0.625 , 0.75 , 0.875 , 1.0 ])
272
+ assert_array_equal (norm (vals ), expected )
273
+
274
+
275
+ def test_DivergingNorm_Odd ():
276
+ norm = mcolors .DivergingNorm (vmin = - 2 , vcenter = 0 , vmax = 5 )
277
+ vals = np .array ([- 2.0 , - 1.0 , 0.0 , 1.0 , 2.0 , 3.0 , 4.0 , 5.0 ])
278
+ expected = np .array ([0.0 , 0.25 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 1.0 ])
279
+ assert_array_equal (norm (vals ), expected )
280
+
281
+
282
+ def test_DivergingNorm_VminEqualsVcenter ():
283
+ with pytest .raises (ValueError ):
284
+ norm = mcolors .DivergingNorm (vmin = - 2 , vcenter = - 2 , vmax = 2 )
285
+
286
+
287
+ def test_DivergingNorm_VmaxEqualsVcenter ():
288
+ with pytest .raises (ValueError ):
289
+ norm = mcolors .DivergingNorm (vmin = - 2 , vcenter = 2 , vmax = 2 )
290
+
291
+
292
+ def test_DivergingNorm_VminGTVcenter ():
293
+ with pytest .raises (ValueError ):
294
+ norm = mcolors .DivergingNorm (vmin = 10 , vcenter = 0 , vmax = 20 )
295
+
296
+
297
+ def test_DivergingNorm_DivergingNorm_VminGTVmax ():
298
+ with pytest .raises (ValueError ):
299
+ norm = mcolors .DivergingNorm (vmin = 10 , vcenter = 0 , vmax = 5 )
300
+
301
+
302
+ def test_DivergingNorm_VcenterGTVmax ():
303
+ vals = np .arange (50 )
304
+ with pytest .raises (ValueError ):
305
+ norm = mcolors .DivergingNorm (vmin = 10 , vcenter = 25 , vmax = 20 )
306
+
307
+
308
+ def test_DivergingNorm_premature_scaling ():
309
+ norm = mcolors .DivergingNorm (vcenter = 2 )
310
+ with pytest .raises (ValueError ):
311
+ norm .inverse (np .array ([0.1 , 0.5 , 0.9 ]))
312
+
313
+
224
314
def test_SymLogNorm ():
225
315
"""
226
316
Test SymLogNorm behavior
0 commit comments