# How to scale a pgfplot in a tikzpicture correctly?

I created a figure in pgfplots and added some extra labels in a tikzfigure environment. Now it turns out I need to rescale the whole figure. Normally this can be done by adding scale=2 but here the scaling is interpreted differently for pgfplots and tikzfigure. The result is rather ugly and I have tried several options but could not fix it. Ideally I want the fontsize not to change at all in both environments.

Here is the MWE and its output:

\documentclass[tikz,12pt]{standalone}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{plotmarks}

\begin{document}

% figure looks fine with:
% \begin{tikzpicture}[scale=1,font=\footnotesize]
% but fonts scale unevenly with:
\begin{tikzpicture}[scale=1.5,font=\footnotesize]

\begin{axis}[name=main plot,
view={45}{45},
ymax=0.4,
xmax=0.16,
zmax=0.6,
y dir=reverse,
xtick={0}, ytick={1}, ztick={1},
extra z ticks={0.5},
extra z tick labels={0.5\,K},
axis lines=center,
]
\addplot3+[blue,fill=blue!40!white, fill opacity=0.5,domain=0:0.233,no markers,samples y=0,samples=50] ({0},{x},{0.419-1.2466E-5*(x+1.30574)^24.19521}) -- (axis cs:0,0,0) -- cycle;
%/*
\tikzset{endpoint/.style={circle,draw=black,fill,inner sep=0pt,minimum size=3pt} }
\node[endpoint] at (axis cs:0,0.23,0) [label=below:{(1)}] {};
%*/
\end{axis}

\node at (0.8,1.6) {$H\perp c$};
\node at (4.5,5) {28\%};

\end{tikzpicture}

\end{document}


Is there an easy way to fix this?

-

## 1 Answer

This is an (unfortunate) artifact of the way how pgfplots aligns its data inside of the tikzpicture: it uses a so-called "cell picture", i.e. a node containing the axis as picture. That node is shifted in order to respect the alignment options. Unfortunately, this appears to make use of the option transform shape (implicitly).

A work-around would be to (a) tell pgfplots to scale its axes (and only its axes) and (b) to tell tikz to scale the rest (and only the rest):

\documentclass[tikz,12pt]{standalone}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{plotmarks}

\begin{document}

% figure looks fine with:
% \begin{tikzpicture}[scale=1,font=\footnotesize]
% but fonts scale unevenly with:
\begin{tikzpicture}[font=\footnotesize]% ----- CF

\begin{axis}[name=main plot,
scale=1.5, % ----- CF
view={45}{45},
ymax=0.4,
xmax=0.16,
zmax=0.6,
y dir=reverse,
xtick={0}, ytick={1}, ztick={1},
extra z ticks={0.5},
extra z tick labels={0.5\,K},
axis lines=center,
]
\addplot3+[blue,fill=blue!40!white, fill opacity=0.5,domain=0:0.233,no markers,samples y=0,samples=50] ({0},{x},{0.419-1.2466E-5*(x+1.30574)^24.19521}) -- (axis cs:0,0,0) -- cycle;
%/*
\tikzset{endpoint/.style={circle,draw=black,fill,inner sep=0pt,minimum size=3pt} }
\node[endpoint] at (axis cs:0,0.23,0) [label=below:{(1)}] {};
%*/
\end{axis}

\begin{scope}[scale=1.5]% ---- CF

\node at (0.8,1.6) {$H\perp c$};
\node at (4.5,5) {28\%};

\end{scope}% ---- CF
\end{tikzpicture}

\end{document}

\end{document}


This solution is ugly, without doubt.

As package author of pgfplots, I will think about improvements.

-
This works nicely for small MWE and also more complicated figures. Thank you for this workaround and the quick response. – Alexander Jul 28 '13 at 15:38
That's good. sorry for making it so complicated. – Christian Feuersänger Jul 29 '13 at 10:37