Skip to content

Commit 041d4e0

Browse files
authored
Merge pull request #24555 from parthpankajtiwary/symlog-warn
ENH: Add warning for SymLogScale when values in linear scale range
2 parents fbfa28d + 6bc9f61 commit 041d4e0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/matplotlib/scale.py

+5
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

+14
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ def test_symlog_mask_nan():
5555
assert type(out) == type(x)
5656

5757

58+
def test_symlog_linthresh():
59+
np.random.seed(19680801)
60+
x = np.random.random(100)
61+
y = np.random.random(100)
62+
63+
fig, ax = plt.subplots()
64+
plt.plot(x, y, 'o')
65+
ax.set_xscale('symlog')
66+
ax.set_yscale('symlog')
67+
68+
with pytest.warns(UserWarning, match="All values .* of linthresh"):
69+
fig.canvas.draw()
70+
71+
5872
@image_comparison(['logit_scales.png'], remove_text=True)
5973
def test_logit_scales():
6074
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)