Skip to content

[Bug]: ax.text() box size determined incorrectly for *-subscript (cuts off text at bottom) #31481

Closed as duplicate

Description

@Dephrilibrium

Bug summary

Hello everyone,

I have the case that I want to add some texual data to a plot. Therefore I need an subscript index for my math-symbol, which became *. It turned out that the text-box cuts off the bottom of the text when just givin * as subscript.

I have created a sample code below which shows the following behaviour:

Image

I tried to overcome that issue by adding a protected space (~) behind * r"$\pm \sigma_{*~}$" but the space is ignored with respect to the box-calculation.

Best regards,
Deph

Code for reproduction

import matplotlib.pyplot as plt

fontSize = 40
fig, ax = plt.subplots(nrows=1, ncols=1)
ax.plot([0, 10],
        [0, 10],
        )
ax.text(0.175, 0.35, r"$\pm \sigma_{e*}$"                                           , transform=ax.transAxes, fontsize=fontSize, ha="left" , va="top")
ax.text(0.175, 0.19, r"$\pm \sigma_{*}$"                                           , transform=ax.transAxes, fontsize=fontSize, ha="left" , va="top")

Actual outcome

See screenshot.

Expected outcome

Text gets not clipped off at bottom

Additional information

Upgraded all packages before issue with pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}
Note: I tested rcparam useTeX=True which worked. However, by that the font changed to the TeX-font. If I consider now using the usetex option means I have to re-finetune the optic a ton of plots.

IDE: VS-Code 1.114.0 (system setup)
VS-Code Plugins: Microsoft Python Plugins Version 2026.4.0

Operating system

Windows 11

Matplotlib Version

3.10.8

Matplotlib Backend

3.10.8

Python version

3.14.3

Jupyter version

N/A

Installation

pip

Activity

  1. changed the title [-][Bug]: ax.text() box size determined incorrectly for *-subscript (cuts of text at bottom)[/-] [+][Bug]: ax.text() box size determined incorrectly for *-subscript (cuts off text at bottom)[/+] on Apr 9, 2026
  2. rcomer commented on Apr 9, 2026

    @rcomer
    Member

    A workaround is to use the \ast (asterisk) command

    ax.text(0.175, 0.35, r"$\pm \sigma_{e\ast}$", transform=ax.transAxes, fontsize=fontSize, ha="left" , va="top")
    ax.text(0.175, 0.19, r"$\pm \sigma_{\ast}$", transform=ax.transAxes, fontsize=fontSize, ha="left" , va="top")
    Image
  3. QuLogic commented on Apr 10, 2026

    @QuLogic
    Member

    This looks like #15313, which was fixed by #30059, and should be fixed in 3.11.

  4. Dephrilibrium commented on Apr 10, 2026

    @Dephrilibrium
    Author

    @rcomer wrote:
    A workaround is to use the \ast (asterisk) command
    ...

    Thanks for the workaroud🙏. It works perfectly. Actually it's quite obvious, but I havent thought so far.

    Best regards,
    Deph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions