1

When I turn on minor ticks in a plot with something like plt.minorticks_on(), I often want to have a larger number of minor ticks.

Is there a simple method to achieve that?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
drevicko
  • 14,382
  • 15
  • 75
  • 97
  • What does "larger" mean? Seems like a read of [this](https://matplotlib.org/3.1.0/gallery/ticks_and_spines/major_minor_demo.html) would be helpful. – BigBen Apr 21 '20 at 01:01

1 Answers1

1

I found a good answer to my question, so in order to be able to find it more quickly next time, I'm including it here:

To have minor ticks every 10 and major ticks every 100 on the x-axis:

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

plt.plot(my_data)
plt.minorticks_on()
ax = plt.gca()
ax.xaxis.set_major_locator(MultipleLocator(100))  # major ticks every 100 (optional)
ax.xaxis.set_minor_locator(MultipleLocator(10))   # minor ticks every 10

In my original plot, ticks defaulted to 100 for major ticks and 20 for minor (5 minor for every major). With this code I get 10 minor ticks for every major.

This is not quite what I was after, but makes it easy enough to get the desired effect.

drevicko
  • 14,382
  • 15
  • 75
  • 97