diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index 21099c8594d5..534165cc72e5 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -389,6 +389,11 @@ def __init__(self, base, linthresh, linscale): def transform_non_affine(self, a): abs_a = np.abs(a) + if (abs_a < self.linthresh).all(): + _api.warn_external( + "All values for SymLogScale are below linthresh, making " + "it effectively linear. You likely should lower the value " + "of linthresh. ") with np.errstate(divide="ignore", invalid="ignore"): out = np.sign(a) * self.linthresh * ( np.power(self.base, diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 7f1130560581..3b70d1e9d31d 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -55,6 +55,20 @@ def test_symlog_mask_nan(): assert type(out) == type(x) +def test_symlog_linthresh(): + np.random.seed(19680801) + x = np.random.random(100) + y = np.random.random(100) + + fig, ax = plt.subplots() + plt.plot(x, y, 'o') + ax.set_xscale('symlog') + ax.set_yscale('symlog') + + with pytest.warns(UserWarning, match="All values .* of linthresh"): + fig.canvas.draw() + + @image_comparison(['logit_scales.png'], remove_text=True) def test_logit_scales(): fig, ax = plt.subplots()