October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Rotate Tick Labels in Matplotlib: 45° and 90°

Use Matplotlib’s tick_params to rotate existing labels by 45° or 90°, or set custom tick positions, text, and rotation together with set_xticks.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.Support on Ko-Fi

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.