Skip to content
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

ticklabel_format reset to default by ScalarFormatter #6330

Closed
gepcel opened this issue Apr 25, 2016 · 7 comments
Closed

ticklabel_format reset to default by ScalarFormatter #6330

gepcel opened this issue Apr 25, 2016 · 7 comments
Milestone

Comments

@gepcel
Copy link
Contributor

gepcel commented Apr 25, 2016

Example:

I want to set ticklabel's as scilimits=(-3, 3) and useMathText=True.
This is what works:

plt.plot(1, 10000, 2, 20000, 'ro')
ax = plt.gca()
ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter(useMathText=True))
ax.ticklabel_format(scilimits=(-3, 3))  # put after 'set_major_formatter', scilimits works
plt.show()

And this is what doesn't work, by switching two line.

plot(1, 10000, 2, 20000, 'ro')
ax = gca()
ax.ticklabel_format(scilimits=(-3, 3))   #put before 'set_major_formatter', scilimits doesn't work.
ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter(useMathText=True))
plt.show()

Reason:

This is what I've find out, I'd like to help, but I don't know weather this should be fixed or how this can be fixed.
In the source code here, every time a ScalarFormatter class was called, those two values (formatter.scientific, and formatter.scilimits) was reset.

Something to mention:

  1. In matplotlib, there are always many more better ways to one same thing. If anyone know some more elegant way of doing this, please let me know. And this way of setting scilimits and useMathText is what I've learned from this very good tutorial.
  2. I've made a commented about this in Ticklabel format not preserved after editing plot limits #6276 . But I'm sure they are relevant or not, so I'm filling this issue here.
@efiring
Copy link
Member

efiring commented Apr 25, 2016

This behavior is fundamental; I don't think it is likely to change. ticklabel_format changes properties of the existing formatter, and yaxis.set_major_formatter connects a new formatter to the y axis. What would be possible is to expose more parameters such as scilimits as kwargs to the ScalarFormatter constructor; and/or to expose more of them (such as useMathText) in ticklabel_format.

@gepcel
Copy link
Contributor Author

gepcel commented Apr 26, 2016

I think to expose useMathText in ticklabel_format would be a better idea. It looks more convenient to do like this:

ax.ticklabel_format(axis='x', scilimits=(-3,3), useMathText=True)

If you agree with this, maybe I can make some changes.

@tacaswell
Copy link
Member

tacaswell commented Apr 26, 2016

You can use get_major_formatter() and poke at it directly.

@gepcel
Copy link
Contributor Author

gepcel commented Apr 26, 2016

Can anyone please examine this?
Thank you.

@gepcel
Copy link
Contributor Author

gepcel commented Apr 29, 2016

Should I close this? I'm new to github.

@tacaswell
Copy link
Member

No, it will automatically close when the pull request is merged.

@tacaswell
Copy link
Member

Closed by #6337

@gepcel if you put closes #ISSUENUMBER in a git commit message that is what triggers the auto closing.

@QuLogic QuLogic added this to the 2.1 (next point release) milestone Apr 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants