11from matplotlib .cbook import MatplotlibDeprecationWarning
22import matplotlib .pyplot as plt
3- from matplotlib .scale import Log10Transform , InvertedLog10Transform
3+ from matplotlib .scale import (Log10Transform , InvertedLog10Transform ,
4+ SymmetricalLogTransform )
45from matplotlib .testing .decorators import check_figures_equal , image_comparison
56
67import numpy as np
8+ from numpy .testing import assert_allclose
79import io
810import platform
911import pytest
@@ -22,6 +24,33 @@ def test_log_scales(fig_test, fig_ref):
2224 ax_ref .plot (xlim , [24.1 , 24.1 ], 'b' )
2325
2426
27+ def test_symlog_mask_nan ():
28+ # Use a transform round-trip to verify that the forward and inverse
29+ # transforms work, and that they respect nans and/or masking.
30+ slt = SymmetricalLogTransform (10 , 2 , 1 )
31+ slti = slt .inverted ()
32+
33+ x = np .arange (- 1.5 , 5 , 0.5 )
34+ out = slti .transform_non_affine (slt .transform_non_affine (x ))
35+ assert_allclose (out , x )
36+ assert type (out ) == type (x )
37+
38+ x [4 ] = np .nan
39+ out = slti .transform_non_affine (slt .transform_non_affine (x ))
40+ assert_allclose (out , x )
41+ assert type (out ) == type (x )
42+
43+ x = np .ma .array (x )
44+ out = slti .transform_non_affine (slt .transform_non_affine (x ))
45+ assert_allclose (out , x )
46+ assert type (out ) == type (x )
47+
48+ x [3 ] = np .ma .masked
49+ out = slti .transform_non_affine (slt .transform_non_affine (x ))
50+ assert_allclose (out , x )
51+ assert type (out ) == type (x )
52+
53+
2554@image_comparison (['logit_scales.png' ], remove_text = True )
2655def test_logit_scales ():
2756 fig , ax = plt .subplots ()
0 commit comments