FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

rotated text does not align · Issue #14239 · matplotlib/matplotlib · GitHub

Repository navigation

rotated text does not align #14239

Closed as duplicate
Closed as duplicate

Description

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

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

Activity

  1. changed the title [-]rotated text does not aligh[/-] [+]rotated text does not align[/+] on May 18, 2019
  2. timhoffm commented on May 18, 2019

    Member

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

    Edit: updated the code to run on recent versions.

  3. github-actions commented on 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!

  4. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Jun 16, 2023
  5. oscargus commented on Jun 16, 2023

    Member

    Related: #23021 #13044

    Maybe related: #14177 #21653

  6. added this to the v3.11.0 milestone on Jun 30, 2025
  7. QuLogic commented on Jun 30, 2025

    Member

    This is a duplicate of #13044 and fixed by #29199.

  8. removed
    keepItems to be ignored by the “Stale” Github Action
    on Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL