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
Whenxtick.labelsize
orytick.labelsize
is small, usingsavefig
withbackend='pgf'
causes the size to render too big. There seems to be a minimum size that these labels can have, but other types of labels do not have this restriction. This bug also requires settingtext.usetex=True
.
Code for reproduction
importmatplotlib.pyplotaspltplt.rcParams.update({'figure.dpi':400,'text.usetex':True,'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_good.png')plt.savefig('my_plot_bad.png',backend='pgf')
Actual outcome
Themy_plot_good.png
file shows the y-axis labels with the correct 1pt font size while themy_plot_bad.png
file shows the same labels with a much bigger font size.
Expected outcome
Both files may look slightly different since two different backends are used, but both files should still show the y-axis label font size as 1pt.
Additional information
There seems to be a discrepancy with how the backend is set. When setting it in rcParam, it produces the incorrect large version, but when setting it as a flag tosavefig
, it produces the correct smaller version.
The above example is for easy reproduction, but my actual original use case was to create a small figure for use in LaTeX. When creating amy_plot.pgf
file that is embedded in a LaTeX document, this bug seems to cause the position of the label to be determined based on the large size, but it will actually render using the small size. This is because the pgf file still sets\fontsize
correctly. When creating a png or pdf file, however, both the position and rendering use the incorrect larger size.
Operating system
Ubuntu
Matplotlib Version
3.7.5
Matplotlib Backend
pgf
Python version
3.8.10
Jupyter version
No response
Installation
pip