Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
Description
Bug summary
When I plot a multiline text usingax.text()
withpath_effects
under TeX environment with package\usepackage[T1]{fontenc}
the multiline coalignment to right breaks.
Code for reproduction
importmatplotlibprint(matplotlib.__version__)importmatplotlib.pyplotaspltfrommatplotlibimportrc_context,patheffectsaspath_effectsprint(matplotlib.get_backend())withrc_context({'text.usetex':True,'font.family':'serif','font.serif':'cm','text.latex.preamble':r'\usepackage[T1]{fontenc}' }):fig,ax=plt.subplots(layout='constrained')text1=ax.text(0,0.95,r'\textbf{aaaaaaaaaaaaaaa}'"\n"+r'\textbf{{\quad\textsc{aaaaaa}}}',transform=ax.transAxes,fontsize=12,va='top',ha='left',linespacing=1.2,ma='left',color='green', )text2=ax.text(0,0.8,r'\textbf{aa}'"\n"+r'\textbf{{aaaaaaaaaaaaaaa}}',transform=ax.transAxes,fontsize=12,va='top',ha='left',linespacing=1.2,ma='right',color='red',path_effects=[path_effects.Stroke(linewidth=1.2,foreground='black'),path_effects.Normal()])text3=ax.text(1,0.95,r'\textbf{aa}'"\n"+r'\textbf{{aaaaaaaaaaaaaaa}}',transform=ax.transAxes,fontsize=12,va='top',ha='right',linespacing=1.2,ma='right',color='red',)text4=ax.text(1,0.8,r'\textbf{aa}'"\n"+r'\textbf{{aaaaaaaaaaaaaaa}}',transform=ax.transAxes,fontsize=12,va='top',ha='right',linespacing=1.2,ma='right',color='red',path_effects=[path_effects.Stroke(linewidth=1.2,foreground='black'),path_effects.Normal()])ax.set_title(r'With \textbackslash usepackage[T1]\{fontenc\}')plt.show()withrc_context({'text.usetex':True,'font.family':'serif','font.serif':'cm', }):fig,ax=plt.subplots(layout='constrained')text1=ax.text(0,0.95,r'\textbf{aaaaaaaaaaaaaaa}'"\n"+r'\textbf{{\quad\textsc{aaaaaa}}}',transform=ax.transAxes,fontsize=12,va='top',ha='left',linespacing=1.2,ma='left',color='green', )text2=ax.text(0,0.8,r'\textbf{aa}'"\n"+r'\textbf{{aaaaaaaaaaaaaaa}}',transform=ax.transAxes,fontsize=12,va='top',ha='left',linespacing=1.2,ma='right',color='red',path_effects=[path_effects.Stroke(linewidth=1.2,foreground='black'),path_effects.Normal()])text3=ax.text(1,0.95,r'\textbf{aa}'"\n"+r'\textbf{{aaaaaaaaaaaaaaa}}',transform=ax.transAxes,fontsize=12,va='top',ha='right',linespacing=1.2,ma='right',color='red',)text4=ax.text(1,0.8,r'\textbf{aa}'"\n"+r'\textbf{{aaaaaaaaaaaaaaa}}',transform=ax.transAxes,fontsize=12,va='top',ha='right',linespacing=1.2,ma='right',color='red',path_effects=[path_effects.Stroke(linewidth=1.2,foreground='black'),path_effects.Normal()])ax.set_title(r'Without \textbackslash usepackage[T1]\{fontenc\}')plt.show()
Actual outcome
Thema='right'
breaks for the bottom two texts withpath_effects
.
Expected outcome
I would expect something similar without\usepackage[T1]{fontenc}
below, but somehow I really want to include it because it provides some additional support, for example, nesting\textsc{}
in\textbf{}
.
Additional information
No response
Operating system
WSL 2.2.4.0/Ubuntu 22.04.3 LTS
Matplotlib Version
3.9.1
Matplotlib Backend
qtagg
Python version
3.12.2
Jupyter version
No response
Installation
None