In Python how to step y minor ticks to given values?
Oct 13, 2:24pm

In Matplotlib, pass minor=True when setting ticks:

python
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 100, 250])

values = [10, 50, 120, 200]  # your given values
ax.set_yticks(values, minor=True)

# optional: style the minor ticks so they're visible
ax.tick_params(axis='y', which='minor', length=3, color='gray')

plt.show()

Key points:

  • ax.set_yticks(values, minor=True) replaces the minor ticks with exactly your list; major ticks stay untouched.
  • If you also want custom major ticks, call ax.set_yticks(major_values) separately (without minor=True).
  • For regularly spaced minor ticks (e.g. 2 between each major), the locator approach is cleaner:
python
from matplotlib.ticker import MultipleLocator
ax.yaxis.set_minor_locator(MultipleLocator(5))  # minor tick every 5 units
  • To label the minor ticks too: ax.set_yticklabels(labels, minor=True) — otherwise they're drawn as unlabelled marks.
Oct 13, 2:24pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more