|
When I use "Times" as font instead of CMR in Python to plot some output, the fonts in the generated figures from Python are matching the printed document in Overleaf, but not matching symbols like "Psi" (if we write in LaTeX: $\Psi$). However, CMR gives a closer output of "Psi" to Overleaf, but fonts need to be a bit bolder to match the printed document in Overleaf. So I do not know which font settings need to be done in the script so that the output will match the Overleaf document. import matplotlib.pyplot as plt import numpy as np plt.rcParams.update({ "text.usetex": True, "font.family": "serif", "font.serif": ["Computer Modern Roman"], #"font.serif": ["CMU Serif"], # Latin Modern "font.size": 10, "axes.labelsize": 10, "xtick.labelsize": 8, "ytick.labelsize": 8, "legend.fontsize": 9, "figure.dpi": 300, "pdf.fonttype": 42, "ps.fonttype": 42, "figure.figsize": (3.5, 2.0), }) try: plt.rcParams['text.latex.preamble'] = r"\usepackage{mathptmx}\usepackage{amsmath,amsfonts}" plt.rcParams["text.latex.preamble"] = "" print("✓ mathptmx preamble set successfully") except Exception as e: print(f"✗ Error with mathptmx preamble: {e}") try: fig, ax = plt.subplots(figsize=(4, 4)) # Test data x = np.linspace(0, 10, 50) y = x + np.random.normal(0, 1, 50) ax.scatter(x, y, s=15, color="#1062ec", alpha=0.9) ax.plot([0, 10], [0, 10], 'k--', alpha=0.7) # Test the problematic Psi labels ax.set_xlabel(r"True $\Psi_{\mathrm{d}}$ / Vs", fontsize=12) ax.set_ylabel(r"Predicted $\Psi_{\mathrm{q}}$ / Vs", fontsize=12) ax.set_title("LaTeX Font Test", fontsize=14) plt.tight_layout() plt.savefig("test_latex_output.pdf", bbox_inches="tight") plt.close() print("✓ Plot with Psi symbols created successfully") print("✓ PDF saved as 'test_latex_output.pdf'") except Exception as e: print(f"✗ Error creating plot with Psi symbols: {e}") import traceback traceback.print_exc()Latex Code: \documentclass[journal]{IEEEtran} \hyphenation{op-tical net-works semi-conduc-tor} \begin{document} \title{Bare Demo of IEEEtran.cls\\ for IEEE Journals} \author{Michael~Shell,~\IEEEmembership{Member,~IEEE,} John~Doe,~\IEEEmembership{Fellow,~OSA,} and~Jane~Doe,~\IEEEmembership{Life~Fellow,~IEEE}% \thanks{M. Shell was with the Department of Electrical and Computer Engineering, Georgia Institute of Technology, Atlanta, GA, 30332 USA e-mail: (see ).}% \thanks{J. Doe and J. Doe are with Anonymous University.}% \thanks{Manuscript received April 19, 2005; revised August 26, 2015.}} \markboth{Journal of \LaTeX\ Class Files,~Vol.~14, No.~8, August~2015}% {Shell \MakeLowercase{\textit{et al.}}: Bare Demo of IEEEtran.cls for IEEE Journals} \maketitle \begin{abstract} The abstract goes here. \end{abstract} \begin{IEEEkeywords} IEEE, IEEEtran, journal, \LaTeX, paper, template. \end{IEEEkeywords} \IEEEpeerreviewmaketitle \section{Introduction} \IEEEPARstart{T}{his} demo file is intended to serve as a ``starter file'' for IEEE journal papers produced under \LaTeX\ using IEEEtran.cls version 1.8b and later. I wish you the best of success. \hfill mds \hfill August 26, 2015 \subsection{Subsection Heading Here} Subsection text here. \subsubsection{Subsubsection Heading Here} Subsubsection text here. True $\Psi$ \the\font \expandafter\show\the\font \section{Conclusion} The conclusion goes here. \appendices \section{Proof of the First Zonklar Equation} Appendix one text goes here. \section{} Appendix two text goes here. \section*{Acknowledgment} The authors would like to thank... \ifCLASSOPTIONcaptionsoff \newpage \fi \begin{thebibliography}{1} \bibitem{IEEEhowto:kopka} H.~Kopka and P.~W. Daly, \emph{A Guide to \LaTeX}, 3rd~ed.\hskip 1em plus 0.5em minus 0.4em\relax Harlow, England: Addison-Wesley, 1999. \end{thebibliography} \begin{IEEEbiography}{Michael Shell} Biography text here. \end{IEEEbiography} \begin{IEEEbiographynophoto}{John Doe} Biography text here. \end{IEEEbiographynophoto} \begin{IEEEbiographynophoto}{Jane Doe} Biography text here. \end{IEEEbiographynophoto} \end{document}The first output comes from Overleaf, and the other from Python.
|



