Skip to content

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

@Dephrilibrium

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

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