0

I am trying to plot with a limited number of ticks in x-axis. I followed this method. And it almost working, however, I have my number scale between 0.1 to 1, and I would still like to do similar operation: only shows[0.2, 0.3, 0.6] in scalar format. The plot is restricted to a log-log plot. And I got this:

overlapping

Obviously, we see the overlapping in [0.2, 0.3, 0.6] and no overlapping for 0.4. How I can remove the original set of the xticks? My program is attached here:

import matplotlib
from matplotlib import pyplot as plt
fig = plt.gcf()
fig.set_size_inches(12, 8)
ax1 = plt.gca()
ax1.plot([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7], [1,2,3, 4, 5, 6, 7])
ax1.set_xscale('log')
ax1.set_yscale('log')

ax1.set_xticks([0.2, 0.3, 0.6])
ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
plt.show()
Lbj_x
  • 415
  • 5
  • 15

1 Answers1

0

Apparently, 0.4 is minor ticks:

fig, ax1 = plt.subplots(figsize=(12,8))
ax1.plot([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7], [1,2,3, 4, 5, 6, 7])
ax1.set_xscale('log')
ax1.set_yscale('log')

ax1.set_xticks([0.2, 0.3, 0.6], minor=False)
ax1.set_xticklabels([],minor=True) # turn minor label off
ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
plt.show()

Output:

enter image description here

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • 1
    You can think of major ticks like `10,20,30...` and minor ticks like `12,14,16,18, 22, 24,26,28...`, i.e. finer grain than major ticks, but may not be as important. – Quang Hoang Jul 04 '19 at 17:23
  • Thanks for the explanation, I was not aware of that before. – Lbj_x Jul 04 '19 at 17:25