Skip to content

Setting axis ticks in log scale produces duplicate tick labels. #11575

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
szsdk opened this issue Jul 5, 2018 · 3 comments · Fixed by #13314
Closed

Setting axis ticks in log scale produces duplicate tick labels. #11575

szsdk opened this issue Jul 5, 2018 · 3 comments · Fixed by #13314
Milestone

Comments

@szsdk
Copy link

szsdk commented Jul 5, 2018

Bug report

Bug summary

Setting axis ticks in a small log scale produces duplicate tick labels.

Code for reproduction

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
s = 10
ax.axis([s, 100, 10, 100])
ax.loglog([20, 30], [30, 40])
from matplotlib.ticker import ScalarFormatter
for axis in [ax.xaxis, ax.yaxis]:
    axis.set_major_formatter(ScalarFormatter())

ax.set_xticks([20, 55])
ax.set_yticks([20, 55])
plt.show()

Actual outcome
figure_1

change code a little bit

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
s = 9
ax.axis([s, 100, 10, 100])
ax.loglog([20, 30], [30, 40])
from matplotlib.ticker import ScalarFormatter
for axis in [ax.xaxis, ax.yaxis]:
    axis.set_major_formatter(ScalarFormatter())
ax.set_xticks([20, 55])
ax.set_yticks([20, 55])
plt.show()

Expected outcome
figure_2

Matplotlib version

  • Operating system: Ubuntu 16.04
  • Matplotlib version: 2.2.2
  • Matplotlib backend: Qt5Agg
  • Python version: 3.6
@ImportanceOfBeingErnest
Copy link
Member

I think there is already an issue about this somewhere around (which I can't find currently).
For some (maybe desired?) reason, minor ticks are labelled as well, depending on the axis bounds.

A workaround is to turn them off.

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
s = 10
ax.axis([s, 100, 10, 100])
ax.loglog([20, 30], [30, 40])
from matplotlib.ticker import ScalarFormatter, NullFormatter
for axis in [ax.xaxis, ax.yaxis]:
    axis.set_major_formatter(ScalarFormatter())
    axis.set_minor_formatter(NullFormatter())

ax.set_xticks([20, 55])
ax.set_yticks([20, 55])
plt.show()

image

@tacaswell
Copy link
Member

See https://matplotlib.org/users/dflt_style_changes.html#logformatter-labeling-of-minor-ticks

The underlying issue is we made the defaults better, but did so in a way that broke people's existing work-arounds.

@timhoffm
Copy link
Member

Related: #13112, #13126.

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

Successfully merging a pull request may close this issue.

5 participants