Skip to main content
Albero Academy

Ticks & Limits

Control the axis range, tick positions and tick labels.

Customizing Plots8 min

Fine control of the axes — where they start and stop, which ticks show, how they're labelled — is often the difference between a chart that misleads and one that's honest and clear.

Axis limits

set the visible range
ax.set_xlim(0, 100)
ax.set_ylim(bottom=0) # force the y-axis to start at zero
ax.set_yscale("log") # log scale for wide-ranging data

Ticks & labels

custom ticks
ax.set_xticks([0, 25, 50, 75, 100])
ax.set_xticklabels(["Q1", "Q2", "Q3", "Q4", "Q5"], rotation=45)
ax.tick_params(axis="y", labelsize=9)

Key takeaways

  1. 01set_xlim/set_ylim control the visible range; set_yscale("log") for wide ranges.
  2. 02set_xticks/set_xticklabels place and label ticks explicitly.
  3. 03Rotate long tick labels to prevent overlap.
  4. 04Start bar/comparison y-axes at zero — a truncated axis misleads.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.