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}
.pgffile should, I think, start with\begin{tikzpicture}, rather than use\resizeboxtry passing the optionalscaleargument to thetikzpictureenvironment, 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.pgffile you can post here to give us something to play with. – Dai Bowen Jun 14 '17 at 13:07pgfbackend of matplotlib generates lower-levelpgfcode, so there is apgfpictureand not atikzpicture, 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:35Is that what you would recommend? Thanks again
– A. Freitas Jun 15 '17 at 08:06pgfstuff, so there may be a way around, but from the comments and answers to the aforementioned questions, it seems matplotlibspgfoutput doesn't really lend itself to scaling, so ifmatplotlib2tikzis 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:43axisenvironment (from the pgfplots package) inside of your .pgf file, then you can manually modify theheightandwidthoptions to it. This will change the size of the canvas on which the plotting is done, but it will not scale anything. In particular, your font size should remain unchanged. It's hard to know whether this will work for you without an example .pgf file. Additionally, the solution isn't ideal since it requires modifying the .pgf files directly instead of rescaling the plots when they're included. – zroth Aug 08 '17 at 14:19However, I am afraid your solution is not suitable in my case because matplotlib does not generate any axis enivronment in the .pgf file. Actually, it creates a pgfpicture and many pgfscope environments inside that picture.
– A. Freitas Aug 09 '17 at 07:44matplotlib2tikzinstead of matplotlib's built-in pgf functionality? – zroth Aug 09 '17 at 19:04