Free tools Windows power users keep installed
One-click scans. No signup required.
To rotate tick labels that are already on a Matplotlib axis, call tick_params on the target axes: ax.tick_params(axis="x", labelrotation=45) for diagonal x-axis labels or use labelrotation=90 for vertical ones. This changes their appearance without changing their text, positions, or formatter.
Rotate existing x- or y-axis tick labels
Use Axes.tick_params when Matplotlib has already chosen the tick locations and labels and you only want to change their angle. The official rotated-label example uses this approach.
ax.tick_params(axis="x", labelrotation=45) # diagonal x-axis labels
ax.tick_params(axis="x", labelrotation=90) # vertical x-axis labels
ax.tick_params(axis="y", labelrotation=45) # rotate y-axis labels
Angles are in degrees. Use axis="x" or axis="y" to specify which set of labels to change. The pyplot equivalent is plt.tick_params(axis="x", labelrotation=45); using ax.tick_params makes the target explicit when a figure has multiple subplots.
Set custom tick positions, labels, and rotation together
If you are assigning your own positions and label text, pass them together to set_xticks. This keeps the tick locations and their labels in one call:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
positions = [0, 1, 2]
labels = ["First category", "Second category", "Third category"]
ax.set_xticks(positions, labels, rotation=45, ha="right")
The Matplotlib 3.10.6 example demonstrates rotation with custom tick labels. Rotation can be given in degrees or as "horizontal" or "vertical". The optional ha="right" aligns angled labels by their right edge, which often makes them easier to scan.
Choose the method that matches the task
| Need | Use | Effect |
|---|---|---|
| Rotate labels already on an axis | ax.tick_params(axis="x", labelrotation=45) |
Changes label appearance while leaving tick locations and formatting alone. |
| Specify positions, labels, and angle together | ax.set_xticks(positions, labels, rotation=45) |
Sets explicit x-tick positions and labels with the requested rotation. |
| Format date labels conveniently | fig.autofmt_xdate() |
Applies date-label rotation and alignment settings. |
The current Axes API index marks Axes.set_xticklabels as discouraged. Avoid using it just to rotate existing labels; use tick_params. When supplying custom labels, use set_xticks with positions and labels together.
Keep rotated labels from being clipped
Angled or vertical text can extend outside the plotting area. Matplotlib’s rotation example creates the figure with constrained layout so labels have room:
fig, ax = plt.subplots(layout="constrained")
For an existing figure, or when that layout argument is not available in your Matplotlib version, adjust the bottom margin if x-axis labels are cut off:
Rank #3
fig.subplots_adjust(bottom=0.25)
Choose the margin based on the label length and rotation, and check the saved figure as well as the notebook display: layout and output bounding determine whether the full labels appear.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Rotate date-axis labels
For date axes, fig.autofmt_xdate() is a convenient formatter. The Figure API documents a default rotation of 30 degrees with right alignment, and a which option for major, minor, or both labels. If you specifically need 45° or 90°, set the desired angle explicitly with tick_params.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




