iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To align Matplotlib y-axis tick labels, set the text alignment on the tick-label Text objects returned by ax.get_yticklabels(). For a typical left-side y-axis, right-align the labels so they extend away from the plot, and set vertical alignment to position each label relative to its tick.
Set horizontal and vertical alignment on y-axis labels
Use each label’s set_horizontalalignment() and set_verticalalignment() methods:
for label in ax.get_yticklabels():
label.set_horizontalalignment("right")
label.set_verticalalignment("center")
Run this after creating the axes and setting up the ticks you want to style. The official Matplotlib alignment example uses the same approach for horizontal alignment. Tick labels are text objects, so their alignment is controlled with text properties rather than a general tick-style setting. See the Matplotlib alignment example and the Axis.set_ticklabels API.
Recommended Free Tools
Choose horizontal alignment for the axis side
For labels on the left side of the axes, "right" alignment places the text’s right edge at the tick anchor, so the label extends left, away from the plotting area. If labels are on the right side, "left" alignment usually serves the same purpose by extending text to the right. Choose a different value when you specifically want the text centered on, or anchored differently from, the tick.
#1 Best Overall
Choose vertical alignment for the tick anchor
"center" aligns the label’s vertical center with its anchor. Other standard Matplotlib text-alignment values can shift which part of the text sits at that anchor. The appropriate choice depends on the intended placement and label content; horizontal and vertical alignment are separate controls.
When to use tick-label objects versus tick styling
Use ax.get_yticklabels() when you need exact horizontal or vertical text alignment. For general tick presentation—such as label size, color, rotation, visibility, or distance from the axis—use ax.tick_params(axis="y", ...). The Matplotlib ticks guide recommends tick_params for bulk tick styling, but it does not expose a general horizontal- or vertical-alignment option.
Rank #2
These methods solve different problems: alignment changes how text sits on its tick anchor; rotation changes its angle; padding changes its distance from the tick; and layout settings control room around the axes. If labels overlap or are clipped, adjust the relevant layout or spacing control rather than assuming alignment alone will fix it. Matplotlib’s tick-label rotation example covers rotation, while constrained layout can help reserve space for labels.
Keep alignment reliable when ticks change
Edits to the objects returned by ax.get_yticklabels() apply to the current tick-label objects. Matplotlib may create, remove, or modify ticks as limits and autoscaling change, so a per-object edit is appropriate for fixed ticks or a static figure, not a guarantee that alignment will persist through interactive view changes. The official Axis ticks guide cautions: “Working with tick instances should only be an option of last resort and requires careful handling to not accidentally overwrite any manual changes through this mechanism.”
If the tick locations and labels should remain fixed, define the positions first and make sure every label corresponds to the intended position. Matplotlib discourages routine use of set_yticklabels() because it depends on tick positions; use ax.set_yticks(...) or a FixedLocator before setting labels when this approach is necessary. The API documentation describes alignment properties accepted by set_ticklabels and the position-matching caveat.
Set a global y-tick alignment default
Matplotlib’s configuration reference includes the ytick.alignment rcParam, whose documented default is center_baseline. This sets a global default; use the individual label objects when you need a per-Axes or per-label adjustment. See the Matplotlib configuration reference.
Rank #4
The linked stable documentation identifies Matplotlib 3.11.2, while the alignment gallery example is in the 3.11.0 documentation. If you rely on version-specific behavior, check the documentation for the Matplotlib release installed in your environment.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.

