Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
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.
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