Skip to content

[ENH]: Warn when a SymLogScale receives values that are all in the linear regime #24550

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

Open
timhoffm opened this issue Nov 26, 2022 · 8 comments
Labels
Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues New feature

Comments

@timhoffm
Copy link
Member

timhoffm commented Nov 26, 2022

Problem

Inspired by #24549. When all values are below linthresh, the SymLogScale looks like a linear scale. This is most certainly not intended by the user.

Proposed solution

Add a warning. This is possibly as simple as adding

if (abs_a < linthresh).all():
    _api.warn_external(
        "All values for SymLogScale are below linthresh, making it effectively "
        "linear. You likely should lower the value of linthresh.")

at

with np.errstate(divide="ignore", invalid="ignore"):

Marking as good first issue. A pull request should contain a test that the warning is actually triggered.

Optional further improvements:

  • Suggest a reasonable value
  • Warn also when there are parts in the log scale, but the screen space would still be dominated by the linear scale. This is not fundamentally difficult, but needs a bit of fiddling with numbers (also including linscale).
  • Investigate whether we can automatically determine linthresh. This may or may not be feasible, because it affects the figure and the place where we have knowledge to do so may not necessarily be the place where such a visual-affecting change could be made.
@timhoffm timhoffm added New feature Good first issue Open a pull request against these issues if there are no active ones! labels Nov 26, 2022
@parthpankajtiwary
Copy link
Contributor

@timhoffm this looks like a fun issue to work on. Can I take it up?

@timhoffm
Copy link
Member Author

Sure. Go for it!

@parthpankajtiwary
Copy link
Contributor

parthpankajtiwary commented Nov 27, 2022

@timhoffm I have created a pull request with the baseline solution and a unit test.

Looking forward to your feedback/change request. In the meantime, I am looking into optional further improvements and will circle back with my findings/questions 🙂

@tacaswell tacaswell added this to the v3.7.0 milestone Nov 28, 2022
@tacaswell
Copy link
Member

Closed by #24555

@parthpankajtiwary
Copy link
Contributor

@timhoffm circling back on the optional further improvements. I wanted to bounce a proposal off of you:

  • suggesting a reasonable value/partial overlap b/w values and linthresh range - my initial thoughts were to work with fractions (fraction of samples that fall within linthresh range) and then agree on an arbitrary fraction (say above 10%) to make suggestions on what might be a reasonable linthresh value (e.g. say we recommend only 10% of the plot fall in linthresh range). Is this a direction we want to pursue?

Looking forward to hearing your thoughts/suggestions on this. Happy to dig deeper and get back with some plots/numbers.

@tacaswell
Copy link
Member

The previously merged implementation caused other problems.

This may be better warned in set_xlim / set_ylim, but getting that right may be more trouble that it is worth.

@saikarna913
Copy link
Contributor

can i try to solve this issue?

@timhoffm timhoffm added Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues and removed Good first issue Open a pull request against these issues if there are no active ones! labels Nov 4, 2024
@timhoffm
Copy link
Member Author

timhoffm commented Nov 4, 2024

@saikarna913 you are welcome to dig into this if you like.

However, I've adjusted the labelling. This is not a good first issue and likely difficult. The straight forward approach outlined in the first comment above and implemented in #24555 lead to false-positives, see #26118, and was thus reverted in #26126.

It's not clear how to properly detect that all values are in the linear regime. To solve this and find a suitable place to warn, one needs deeper understanding of scales, the transforms system and how they are used within Matplotlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues New feature
Projects
None yet
Development

No branches or pull requests

4 participants