Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ScalarFormatter.set_powerlimits documentation seems inconsistent #15376

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
cmbant opened this issue Oct 3, 2019 · 3 comments · Fixed by #17590
Closed

ScalarFormatter.set_powerlimits documentation seems inconsistent #15376

cmbant opened this issue Oct 3, 2019 · 3 comments · Fixed by #17590
Milestone

Comments

@cmbant
Copy link

cmbant commented Oct 3, 2019

Bug report

Documentation says:

set_powerlimits(self, lims)[source]
Sets size thresholds for scientific notation.
(min_exp, max_exp)
A tuple containing the powers of 10 that determine the switchover threshold. Numbers below 10**min_exp and above 10**max_exp will be displayed in scientific notation.

However

    sFormatter = matplotlib.ticker.ScalarFormatter(useOffset=False, useMathText=True)
    sFormatter.set_powerlimits((-2, 2))
    plt.plot([120,130,140],[0.03,0.05,0.08])
    plt.gca().xaxis.set_major_formatter(sFormatter)
    plt.gca().yaxis.set_major_formatter(sFormatter)

does use scientific notation on the y axis but not the x axis. The the correct description of the actual behaviour seems to be

A tuple containing the powers of 10 that determine the switchover threshold. Numbers with absolute values below 10**(min_exp+1) and above 10**(max_exp+1) will be displayed in scientific notation.

Or it is a bug (would make more sense if the original description were correct).

@ImportanceOfBeingErnest
Copy link
Member

A confusing bit is that you are using the same formatter for both axes. If using a dedicated formatter per axis it would give

import matplotlib.ticker
import matplotlib.pyplot as plt

sFormatter1 = matplotlib.ticker.ScalarFormatter(useOffset=False, useMathText=True)
sFormatter1.set_powerlimits((-2, 2))

sFormatter2 = matplotlib.ticker.ScalarFormatter(useOffset=False, useMathText=True)
sFormatter2.set_powerlimits((-2, 2))

plt.plot([120,130,140],[0.03,0.05,0.08])
plt.gca().xaxis.set_major_formatter(sFormatter1)
plt.gca().yaxis.set_major_formatter(sFormatter2)

plt.show()

image

Still, the sentence in the documentation remains incorrect (or at least not detailed enough), as seen from the y axis.

@anntzer
Copy link
Contributor

anntzer commented Oct 4, 2019

As a general rule a single formatter instance cannot be used across multiple axises --- though #13482 fixes that :)

@timhoffm
Copy link
Member

timhoffm commented Jun 8, 2020

Reusing formatters is off-topic.

The actual issue is a documentation issue. IMHO it's not a bug, but one has to think about the limits in the right way, see #17590.

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.

4 participants