Aabestfontgenerator.
THE TYPE NOTEBOOK

Matplotlib Axis and Tick Label Font Sizes

Use Matplotlib to size x and y axis labels separately from tick labels, and proof long units and numbers in the exported chart.

Set axis titles and tick numbers separately. Compare them in the exported figure at the size the audience will see.

Sources reviewed .

01

Set the axis titles on the intended Axes

Matplotlib documents set_xlabel and set_ylabel as the methods for the text naming an axis. For example, use ax.set_xlabel("Time (s)", fontsize=12) and ax.set_ylabel("Distance (m)", fontsize=12). Apply the calls to the Axes object containing the actual plot. Keep the units in the label if the figure needs them.

02

Set the scale numbers separately

For existing tick labels, try ax.tick_params(axis="both", labelsize=9). Use axis="x" if the change applies only to the horizontal scale. A title such as Time (s) and the numbers below it are different text objects. Compare them together before increasing all text settings globally.

03

Proof the exported panel at final size

Include the longest axis title and the most crowded run of tick labels. If they overlap, compare fewer ticks or a larger panel before shrinking the words. Export using the intended figure size and inspect it in the final document. For a separate copyable chart caption, try the homepage text-style tool.

GOOD QUESTIONS

Your questions, answered.

Why did changing the axis title size leave the numbers unchanged?

The title and tick numbers are separate. Use the axis title method for the first and tick_params for the second.

How can I change tick labels on only one axis?

Set the axis argument to x or y on the intended Axes object.

Sources & background

Sources supporting this page’s explanations. Practical examples are our editorial suggestions.