# Scaling PGF plots and its font independently

I am a PhD student, quite new to the fantastic LaTeX world. Although I have written sevral documents already, I am still a beginner, and definitely not a programmer. I am using Python for my research, and matplotlib to genereate graphs. As I am addicted to vector graphics, I want to create and save vector plots via matplotlib under python, with the .pgf format.

I am struggling with the following issue : I have saved my plots with no preferred figsize, as I wanted the plots to be flexible and to adapt to any size constraint. My problem is the following : How can I rescale a .pgf file without changing the font size? I have tried many many solutions.

What I do for the moment is the following : if I want to have 2 plots side-by-side, I create two minipages, inside of which I use rescalebox in order to force the pgfplot to scale to the size of the minipage.

Sadly, my plots are a bit too complicated for tikz. I have tried with the package matplotlib2tikz. It distorts the picture and makes it look ugly. Also, the backend is not exactly the same than pgf/matplotlib, bringing inconsistence in the document. Of course, I do prefer the pgf one :).

Despite all my research, I could not find any solution. Do you guys have anything that could help me? Thanks so much in advance,

Best,

AF

I am joining a MWE here, but not the .pgf files, as they are ~4300 lines long :

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}

\usepackage{pgfplots}
\usepackage{graphicx}
\usepackage{caption} % ! Caption THEN Label !
\usepackage{subcaption} % ! minipage environment requires textwidth !
\captionsetup[subfigure]{labelformat=parens,labelsep=space}

\begin{document}
\begin{figure}
\centering
\captionsetup[subfigure]{justification=centering}
\begin{minipage}{0.49 \linewidth}
\centering
\resizebox{\linewidth}{!}{
\input{cryst_50.pgf}
}
\subcaption{Crystalline contribution at \SI{50}{\second} reaction time.}
\label{cryst_50}
\end{minipage}
\begin{minipage}{0.49 \linewidth}
\centering
\resizebox{\linewidth}{!}{\input{cryst_3560.pgf}}
\subcaption{Crystalline contribution at \SI{3560}{\second} reaction time.}
\label{cryst_3560}
\end{minipage}
\caption{Examples of crystalline signal.}
\label{cryst examples}
\end{figure}
\end{document}

• Welcome to TeX.SX! The .pgf file should, I think, start with \begin{tikzpicture}, rather than use \resizebox try passing the optional scale argument to the tikzpicture environment, i.e. \begin{tikzpicture}[scale=0.5] to resize the graphic part while preserving text size. Otherwise can you generate some very simple graphs which produce a shorter .pgf file you can post here to give us something to play with. – Dai Bowen Jun 14 '17 at 13:07
• @DaiBowen No, I believe the pgf backend of matplotlib generates lower-level pgf code, so there is a pgfpicture and not a tikzpicture, and judging by some previous questions on the site, there is no obvious, convenient way of scaling them. – Torbjørn T. Jun 14 '17 at 17:35
• I would actually recommend that you set the size of your figure in Python, so that you don't have to do any scaling. But some previous questions about more or less the same topic (not too many answers though): tex.stackexchange.com/questions/148296 tex.stackexchange.com/questions/134274 tex.stackexchange.com/questions/165042 tex.stackexchange.com/questions/328281 (tex.stackexchange.com/questions/196368) – Torbjørn T. Jun 14 '17 at 17:46
• Thanks Torbjørn for your answer! To be honest, I had a look to all links you provided. None of these solutions satisfy me, because of how complicated the plots can be. Sadly, I indeed think this is the only solution. Do you know how I can retrieve standard figure sizes for LaTeX documents? I guess I can retrieve the total width and plot my graphs with an accordingly defined figsize. Is that what you would recommend? Thanks again – A. Freitas Jun 15 '17 at 8:06
• I don't think there is a standard size, it depends on the figure itself and the layout of the document. You can have a look at e.g. tex.stackexchange.com/a/339586 to find how wide the textblock of a document is. Now, I'm not well versed in the lower level pgf stuff, so there may be a way around, but from the comments and answers to the aforementioned questions, it seems matplotlibs pgf output doesn't really lend itself to scaling, so if matplotlib2tikz is not an option, then that is what I would do (and have done, only with PDF output). – Torbjørn T. Jun 15 '17 at 19:43