X Tutup
Skip to content

ticklabel_format reset to default by ScalarFormatter #6330

@gepcel

Description

@gepcel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup