Description
Bug summary
The text.usetex
rcParam flag can be used to enable TeX rendering on all Text elements instead of Mathtext. When using the pgf backend, I would expect this flag to have no effect and for the Text elements to be rendered identically since pgf also uses TeX to render.
The problem is that the usetex
renderer seems to have a different implementation than the pgf
renderer.
Code for reproduction
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.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 objects
fig, ax = plt.subplots(figsize=(2, 1.5))
# Plot the data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
ax.plot(x, y)
# Set the title and axis labels
ax.set_title('My Plot')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
# Save the plot to a file
plt.savefig('my_plot.png')
plt.savefig('my_plot.pgf')
Actual outcome
When text.usetex
is True
, the tick labels use display math font to render in Tex.
When text.usetex
is False
, the tick labels use the regular text font to render in Tex.
Expected outcome
When using the pgf backend, I would expect enabling/disabling text.usetex
to have no effect on the output.
Additional information
From what I understand, the text.usetex
implementation has an unofficially supported rcParam for the preamble named text.latex.preamble
. On the other hand, the pgf implementation has an officially supported rcParam for the preamble named pgf.preamble
. From the documentation it's unclear to me which renderer/preamble takes precedence when both pgf and usetex
are enabled.
The text.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