8000 ENH: Add warning for SymLogScale when values in linear scale · matplotlib/matplotlib@15571fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 15571fc

Browse files
ENH: Add warning for SymLogScale when values in linear scale
1 parent fbfa28d commit 15571fc

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/matplotlib/scale.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ def __init__(self, base, linthresh, linscale):
389389

390390
def transform_non_affine(self, a):
391391
abs_a = np.abs(a)
392+
if (abs_a < self.linthresh).all():
393+
_api.warn_external(
394+
"All values for SymLogScale are below linthresh, making "
395+
"it effectively linear. You likely should lower the value "
396+
"of linthresh. ")
392397
with np.errstate(divide="ignore", invalid="ignore"):
393398
out = np.sign(a) * self.linthresh * (
394399
np.power(self.base,

lib/matplotlib/tests/test_scale.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import io
1515
import pytest
1616

17+
import random
18+
1719

1820
@check_figures_equal()
1921
def test_log_scales(fig_test, fig_ref):
@@ -55,6 +57,25 @@ def test_symlog_mask_nan():
5557
assert type(out) == type(x)
5658

5759

60+
def test_symlog_linthresh():
61+
fig, ax = plt.subplots()
62+
63+
n_samples = 100
64+
65+
upper_bound = 1.0
66+
67+
x = [random.uniform(0.0, upper_bound) for _ in range(n_samples)]
68+
y = [random.uniform(0.0, upper_bound) for _ in range(n_samples)]
69+
70+
with pytest.warns(UserWarning) as record:
71+
plt.plot(x, y, 'o')
72+
ax.set_xscale('symlog')
73+
ax.set_yscale('symlog')
74+
plt.show()
75+
76+
assert len(record) == 1
77+
78+
5879
@image_comparison(['logit_scales.png'], remove_text=True)
5980
def test_logit_scales():
6081
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)
0