Skip to content

[Bug]: symlog scale generates false warning when mouse is moved #26118

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

Closed
jxjo opened this issue Jun 13, 2023 · 11 comments · Fixed by #26126
Closed

[Bug]: symlog scale generates false warning when mouse is moved #26118

jxjo opened this issue Jun 13, 2023 · 11 comments · Fixed by #26126

Comments

@jxjo
Copy link

jxjo commented Jun 13, 2023

Bug summary

When using symlog scale for an axis, a false warning is initially generated - independant of the data to plot - as soon as the mouse is moved over the axes.

Code for reproduction

import matplotlib.pyplot as plt

ax = plt.figure().add_subplot()
ax.set_yscale('symlog')

plt.show()

Actual outcome

UserWarning: All values for SymLogScale are below linthresh, making it effectively linear. You likely should lower the value of linthresh.

Expected outcome

"Nothing"

Additional information

... maybe related to TkAgg?

Operating system

Windows

Matplotlib Version

3.7.0

Matplotlib Backend

TkAgg

Python version

3.11.2

Jupyter version

No response

Installation

pip

@tacaswell
Copy link
Member

tacaswell commented Jun 13, 2023

I do not think this warning is erroneous and I see it as soon as the window shows (not on mouse motion). It is warning you that given the current data limits symlog is not doing anything for you (because you are fully in the linear range).

If you do:

import matplotlib.pyplot as plt

ax = plt.figure().add_subplot()
ax.set_yscale('symlog')
ax.set_ylim(0, 1000)
plt.show()

you will not see the warning.

@tacaswell
Copy link
Member

I was fooled by the default limits triggering the warning.

I can reproduce this on mouse motion.

@tacaswell tacaswell added this to the v3.7.2 milestone Jun 13, 2023
@ksunden
Copy link
Member

ksunden commented Jun 13, 2023

if (abs_a < self.linthresh).all():

ndarray.all() is true for an empty ndarray, and thus this should probably be changed to

if len(abs_a)>0 and ...:

or short circuit and return earlier, before even calling abs.

@ksunden ksunden added the Good first issue Open a pull request against these issues if there are no active ones! label Jun 13, 2023
@github-actions
Copy link

Good first issue - notes for new contributors

This issue is suited to new contributors because it does not require understanding of the Matplotlib internals. To get started, please see our contributing guide.

We do not assign issues. Check the Development section in the sidebar for linked pull requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please collaborate on the work by reviewing it rather than duplicating it in a competing PR.

If something is unclear, please reach out on any of our communication channels.

@jxjo
Copy link
Author

jxjo commented Jun 13, 2023

... yep - the question is, "who" sends these false empty values as the warning is also raised if valid data is plotted...

@jklymak
Copy link
Member

jklymak commented Jun 13, 2023

I'm not a fan of having a warning here at all. People who don't understand symlog sometimes get confused, but I don't think that means we should spam potentially valid usage.

@ksunden
Copy link
Member

ksunden commented Jun 13, 2023

Looks like it is actually in format_coord (specifically in this example format_xdata, which is odd, considering the y value is the one with the scale set...)

This is the method which gives the text which displays in the toolbar. It probably gets a single value, or a small number of values for neighboring pixels to determine what level of precision to display... at which point yeah...

I think I agree with @jklymak that we should not be warning here... perhaps keep a warning on setting limits (potentially even auto limits, but I'm tempted to say only when explicitly setting limits), rather than just when transforming, which is not the right place for a warning...

I'll remove the Good first issue label at least while we solidify the path forward... (I originally thought this was a simple 1-3 line change, but now see it is a bit more complicated)

@ksunden ksunden removed the Good first issue Open a pull request against these issues if there are no active ones! label Jun 13, 2023
@ksunden
Copy link
Member

ksunden commented Jun 13, 2023

Actually, it is in the inverted symlog transform (and only the inverted transform)..., it was originally implemented for mpl 3.7.0 in #24555, but the idea stems from the issue #24550.

I don't know that there is a much better hook if we do want a warning somewhere, but it does feel odd/limiting to warn whenever points in only the linear region are passed through the inverse transform...

It is equally useless to use symlog (compared to just log) if all your points are in the positive side of the log portion of symlog, but there is no warning then (and in fact if you set ylim to (100, 1000) before showing there is no warning for the example...)... It is less unexpected as you setting to a log behavior and getting a log behavior, but still.

Perhaps @timhoffm can weigh in here, as author of the issue requesting this warning.

@jxjo
Copy link
Author

jxjo commented Jun 14, 2023

... from my point of view, the warning itself is not the "problem". Here is a valid example throwing the same warning, when mouse is moved:

    import matplotlib.pyplot as plt
    ax = plt.figure().add_subplot()

    ax.set_yscale('symlog')
    x = np.linspace(-100,100,200)
    ax.plot(x, x)

    plt.show()

I think, there are 2 issues. The bug in transform_non_affine, which should be like ...

  • if values are None or length==0, do nothing
  • if length==1, no test, no warning but transform
  • if length>1, test, warning and transform

... and the bug in the mouse coordinate driver, which sends obviously (see above @ksunden ) None or length==0 values.


Regarding the warning itself:

If I have one diagram which I use for different datasets - and all points of one dataset are within the linear threshold, then this is a valid case - no reason to warn.

Or in common: The warning is wrong ;-) and should be removed again.


For completeness: As a workaround the warning can be suppressed for example with

    import warnings
    warnings.filterwarnings("ignore", message = "All values for SymLogScale")

@anntzer
Copy link
Contributor

anntzer commented Jun 14, 2023

FWIW I would agree with removing the warning.

@tacaswell
Copy link
Member

In further inspection, it looks like this is warning on the inverse (not the forward) transform that happens to also be called in the case that is tested (as part of sorting out how much the margin should be).

Even if we move this to the correct transform, there are still too many places where we want to pass data just in range (e.g. we call the forward transform on mouse motion to estimate the pixel-to-pixel data range and ensure that the values printed in the toolbar are reasonably precise)

I am going to open a PR to revert #24555 and reopen #24550.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jun 14, 2023
…mlog-warn"

This reverts commit 041d4e0, reversing
changes made to fbfa28d.

Closes matplotlib#26118
melissawm pushed a commit to melissawm/matplotlib that referenced this issue Jun 15, 2023
…mlog-warn"

This reverts commit 041d4e0, reversing
changes made to fbfa28d.

Closes matplotlib#26118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants