Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
When using Matplotlib to generate PGF files with theIEEEtran
document class, I noticed that if the legend font size is smaller than 5, extra whitespace appears on the right side. Currently, my workaround is to forcibly override the defaultarticle
document class, which avoids this issue.
Would it be possible to provide an interface allowing users to directly modify the documentclass used by Matplotlib? Below is the reproducible code and a screenshot demonstrating the issue.
\documentclass{IEEEtran}\usepackage{pgf}\begin{document}\input{main.pgf}\end{document}
Overriding the default definition can resolve this issue.
importmatplotlibimportmatplotlib.pyplotaspltimportmatplotlib.backends.backend_pgfmatplotlib.backends.backend_pgf._DOCUMENTCLASS=r"\documentclass{IEEEtran}"if__name__=='__main__':matplotlib.rcParams['pgf.texsystem']='pdflatex'fig,ax=plt.subplots(figsize=(2,2),constrained_layout=True)ax.plot([1,2,3,4,5], [5,5,5,5,5],label='legend')ax.plot([1,2,3,4,5], [5,5,5,5,5],label='test legend')legend=ax.legend(fontsize=2)pfg_file='main.pgf'plt.savefig(pfg_file,transparent=True)plt.close()
Code for reproduction
importmatplotlibimportmatplotlib.pyplotaspltif__name__=='__main__':matplotlib.rcParams['pgf.texsystem']='pdflatex'fig,ax=plt.subplots(figsize=(2,2),constrained_layout=True)ax.plot([1,2,3,4,5], [5,5,5,5,5],label='legend')ax.plot([1,2,3,4,5], [5,5,5,5,5],label='test legend')legend=ax.legend(fontsize=2)pfg_file='main.pgf'plt.savefig(pfg_file,transparent=True)plt.close()
Actual outcome
Expected outcome
Additional information
No response
Operating system
No response
Matplotlib Version
3.10.0
Matplotlib Backend
No response
Python version
3.12.4
Jupyter version
No response
Installation
pip