Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: leading whitespace in legend and labels ignored with usetex=True #24166

Open
@lukashergt

Description

@lukashergt

Bug summary

As raised in aquestion on stackoverflow, none of the typical latex commands for horizontal white space (e.g.~,\,,\quad,\hphantom{whitespace}) seem to work at the start of a text label when usingtext.usetex=True.

The commands work as expected in the middle of a text label.

Code for reproduction

importmatplotlib.pyplotaspltplt.rcParams['font.family']='serif'plt.rcParams['text.usetex']=Trueplt.rcParams['mathtext.fontset']='cm'fig=plt.figure(figsize=(4,3))plt.plot([],label="~ tilde $\\sim$")plt.plot([],label="\, comma\\textbackslash,")plt.plot([],label="\quad\\textbackslash quad")plt.plot([],label="\hphantom{whitespace}\\textbackslash hphantom")plt.plot([],label=".\hphantom{whitespace} ugly leading dot")plt.plot([],label=".whitespace ugly leading dot")plt.xlabel("\hphantom{whitespace} xlabel")plt.legend()

Actual outcome

As you can see in the image below, none of the horizontal white space commands seem to be doing anything as long as they are at the head of the legend label or xlabel.

They all work fine when starting with some other character. Compare legend labels 4, 5, and 6.\hphantom{whitespace} doesn't do anything in label 4, but in label 5 after a leading dot it correctly produces exactly the amount of white space that matches the horizontal space of the wordwhitespace as shown in label 6.

no leading whitespace

Expected outcome

The latex commands~,\,,\quad,\hphantom{whitespace} should produce horizontal white space even when at the start of a text label.

System

  • Operating system: Manjaro Linux
  • Matplotlib Version: 3.6.1
  • Matplotlib Backend:module://matplotlib_inline.backend_inline
  • Python version: 3.10.7
  • Jupyter version: 6.4.12 (notebook), 3.4.7 (lab)
  • Installation: pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp