8000 Add a test for the transform and its inverse · matplotlib/matplotlib@e2c460e · GitHub
[go: up one dir, main page]

Skip to content

Commit e2c460e

Browse files
committed
Add a test for the transform and its inverse
1 parent b218e7c commit e2c460e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/matplotlib/tests/test_scale.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from matplotlib.cbook import MatplotlibDeprecationWarning
22
import matplotlib.pyplot as plt
3-
from matplotlib.scale import Log10Transform, InvertedLog10Transform
3+
from matplotlib.scale import (Log10Transform, InvertedLog10Transform,
4+
SymmetricalLogTransform)
45
from matplotlib.testing.decorators import check_figures_equal, image_comparison
56

67
import numpy as np
8+
from numpy.testing import assert_allclose
79
import io
810
import platform
911
import 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)
2655
def test_logit_scales():
2756
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)
0