Skip to content

ENH: Add warning for SymLogScale when values in linear scale range #24555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down