Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rotated text does not align #14239

Open
chapochn opened this issue May 18, 2019 · 3 comments
Open

rotated text does not align #14239

chapochn opened this issue May 18, 2019 · 3 comments
Labels
keep Items to be ignored by the “Stale” Github Action status: confirmed bug topic: text

Comments

@chapochn
Copy link

Bug report

Bug summary

rotating different text by 90 degrees give different baseline alignment

Code for reproduction

import matplotlib.pyplot as plt
plt.figure(figsize=(2., 2.))
plt.text(0.5, 0.0, 'yB', fontsize=40, rotation=90)
plt.text(0.5, 0.5, 'By', fontsize=40, rotation=90)
plt.show()

Actual outcome
Figure_1

Expected outcome

Expected 'yB' and 'By' to be aligned

Matplotlib version

  • Operating system: CentOS Linux 7
  • Matplotlib version: 3.0.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.8

installed via conda

@chapochn chapochn changed the title rotated text does not aligh rotated text does not align May 18, 2019
@timhoffm
Copy link
Member

timhoffm commented 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:

grafik

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()

Edit: updated the code to run on recent versions.

@github-actions
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 16, 2023
@oscargus oscargus added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 16, 2023
@oscargus
Copy link
Contributor

oscargus commented Jun 16, 2023

Related: #23021 #13044

Maybe related: #14177 #21653

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action status: confirmed bug topic: text
Projects
None yet
Development

No branches or pull requests

4 participants