1
1
from matplotlib .cbook import MatplotlibDeprecationWarning
2
2
import matplotlib .pyplot as plt
3
- from matplotlib .scale import Log10Transform , InvertedLog10Transform
3
+ from matplotlib .scale import (Log10Transform , InvertedLog10Transform ,
4
+ SymmetricalLogTransform )
4
5
from matplotlib .testing .decorators import check_figures_equal , image_comparison
5
6
6
7
import numpy as np
8
+ from numpy .testing import assert_allclose
7
9
import io
8
10
import platform
9
11
import pytest
@@ -22,6 +24,33 @@ def test_log_scales(fig_test, fig_ref):
22
24
ax_ref .plot (xlim , [24.1 , 24.1 ], 'b' )
23
25
24
26
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
+
25
54
@image_comparison (['logit_scales.png' ], remove_text = True )
26
55
def test_logit_scales ():
27
56
fig , ax = plt .subplots ()
0 commit comments