How to influence the size of a tikzpicture generated from Python using tikzplotlib?
As described in the Readme, tikzplotlib
has the possibility of setting the width and/or height of the plots, using the figurewidth
/figureheight
keys for tikz_save
:
tikz_save('someplot.tex', figureheight='5cm', figurewidth='9cm')
I believe that these lengths refer to the size of the axis box alone, not including ticklabels, axis labels and titles.
You can alternatively set the values to macros, and define lengths by those names in your document, i.e.
tikz_save(
'someplot.tex',
figureheight = '\\figH',
figurewidth = '\\figW'
)
and in your LaTeX document:
\documentclass{article}
\usepackage{pgfplots,amsmath}
\newlength\figH
\newlength\figW
\setlength{\figH}{4cm}
\setlength{\figW}{8cm}
\begin{document}
Some text, then a centred plot:
\begin{center}
\input{firstplot}
\end{center}
More text, then a wider plot:
\begin{center}
\setlength{\figW}{10cm} % when added inside the center environment it has no effect outside it
\input{secondplot}
\end{center}
\end{document}
This is basically the same as for matlab2tikz
(See my answer to tikz+matlab2tikz), except that the key is figurewidth
/figureheight
, instead of width
/height
.
In version 0.9.3 you seem to need axis_height
and axis_width
, rather than figureheight
and figurewidth
.