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
Thetext.usetex
rcParam flag can be used to enableTeX rendering on all Text elements instead ofMathtext. When using the pgf backend, I would expect this flag to have no effect and for the Text elements to be rendered identically sincepgf also uses TeX to render.
The problem is that theusetex
renderer seems to have a different implementation than thepgf
renderer.
Code for reproduction
importmatplotlib.pyplotaspltimportmatplotlibasmplmpl.use('pgf')plt.rcParams.update({'figure.dpi':400,'text.usetex':True,# TODO: comment this out to get different results'ytick.labelsize':1, })# Create the figure and axis objectsfig,ax=plt.subplots(figsize=(2,1.5))# Plot the datax= [1,2,3,4,5]y= [2,4,6,8,10]ax.plot(x,y)# Set the title and axis labelsax.set_title('My Plot')ax.set_xlabel('X-axis')ax.set_ylabel('Y-axis')# Save the plot to a fileplt.savefig('my_plot.png')plt.savefig('my_plot.pgf')
Actual outcome
Whentext.usetex
isTrue
, the tick labels use display math font to render in Tex.
Whentext.usetex
isFalse
, the tick labels use the regular text font to render in Tex.
Expected outcome
When using the pgf backend, I would expect enabling/disablingtext.usetex
to have no effect on the output.
Additional information
From what I understand, thetext.usetex
implementation has an unofficially supported rcParam for the preamble namedtext.latex.preamble
. On the other hand, the pgf implementation has an officially supported rcParam for the preamble namedpgf.preamble
. From the documentation it's unclear to me which renderer/preamble takes precedence when both pgf andusetex
are enabled.
Thetext.usetex
renderer also does not support XeLaTeX/LuaLaTeX according to the documentation.
In conclusion:
Is there any reason why these two rendering engines can not (or should not) be unified? I suspect this is also the root cause of a lot of confusion and consistency errors people have.
Related:
#28084
Operating system
Ubuntu
Matplotlib Version
3.7.5
Matplotlib Backend
pgf
Python version
3.8.10
Jupyter version
No response
Installation
pip