You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A modified version of the text rotation example shows that the bbox is at the correct place but the text is not rendered in the correct position relative to the bbox:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.axes_grid import ImageGrid
def test_rotation_mode(fig, mode, subplot_location):
ha_list = ["left", "center", "right"]
va_list = ["top", "center", "baseline", "bottom"]
grid = ImageGrid(fig, subplot_location,
nrows_ncols=(len(va_list), len(ha_list)),
share_all=True, aspect=True, cbar_mode=None)
# labels and title
for ha, ax in zip(ha_list, grid.axes_row[-1]):
ax.axis["bottom"].label.set_text(ha)
for va, ax in zip(va_list, grid.axes_column[0]):
ax.axis["left"].label.set_text(va)
grid.axes_row[0][1].set_title(f"rotation_mode='{mode}'", size="large")
if mode == "default":
kw = dict()
else:
kw = dict(
bbox=dict(boxstyle="square,pad=0.", ec="none", fc="C1", alpha=0.3))
# use a different text alignment in each axes
texts = {}
for (va, ha), ax in zip([(x, y) for x in va_list for y in ha_list], grid):
# prepare axes layout
for axis in ax.axis.values():
axis.toggle(ticks=False, ticklabels=False)
ax.axvline(0.5, color="skyblue", zorder=0)
ax.axhline(0.5, color="skyblue", zorder=0)
ax.plot(0.5, 0.5, color="C0", marker="o", zorder=1)
# add text with rotation and alignment settings
tx = ax.text(0.5, 0.5, 'yB',
size=20, rotation=90,
horizontalalignment=ha, verticalalignment=va,
rotation_mode=mode, **kw)
tx2 = ax.text(0.5, 0.515, 'By',
size=20, rotation=90,
horizontalalignment=ha, verticalalignment=va,
rotation_mode=mode, **kw)
texts[ax] = (tx, tx2)
if mode == "default":
# highlight bbox
fig.canvas.draw()
for ax, txts in texts.items():
for tx in txts:
bb = tx.get_window_extent().transformed(ax.transData.inverted())
rect = plt.Rectangle((bb.x0, bb.y0), bb.width, bb.height,
facecolor="C1", alpha=0.3, zorder=2)
ax.add_patch(rect)
fig = plt.figure(figsize=(16, 12))
test_rotation_mode(fig, "default", 121)
test_rotation_mode(fig, "anchor", 122)
plt.show()
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
[-]rotated text does not aligh[/-][+]rotated text does not align[/+]timhoffm commentedon May 18, 2019
A modified version of the text rotation example shows that the bbox is at the correct place but the text is not rendered in the correct position relative to the bbox:
Edit: updated the code to run on recent versions.
github-actions commentedon Jun 16, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
oscargus commentedon Jun 16, 2023
Related: #23021 #13044
Maybe related: #14177 #21653
QuLogic commentedon Jun 30, 2025
This is a duplicate of #13044 and fixed by #29199.