[Tex/LaTex] font size scaling and node placement issues using pgfplots and tikzscale

pgfplotstikzscale

From the tikzscale documentation I understand, that it is supposed to keep font sizes constant. However, this does not seem to apply to axis ticks or axis labels from pgfplots' axis environment. Also, node placement seems to be messed up. This is illustrated in the following example:

\documentclass[10pt,crop]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepackage{tikzscale}
\usepackage{filecontents}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{filecontents}{font-size.tikz}
\begin{tikzpicture}
  \begin{axis}[
  width=150pt,
  height=150pt,
  xmin=-1,xmax=1,ymin=-1,ymax=1,
  xlabel=xlabel,
  ylabel=ylabel,
  ]
  \addplot coordinates{ 
  (-0.9,-0.9)
  (0.9,0.9)
  };
  \node[anchor=west] at (axis cs:-1,0) {01};
  \coordinate (a) at (axis cs:-1,0);
  \end{axis}
  \node[anchor=west,red] at (a) {02};
\end{tikzpicture}
\end{filecontents}

Some text in font size 10pt.
\input{font-size.tikz}
\includegraphics[width=250pt]{font-size.tikz}
\end{document}

enter image description here
In the first plot, created without tikzscale, all labels and nodes have the correct font size and node "02" is placed correctly. In the second plot, however, font sizes for the labels are obviously larger. The same holds for node "01". Interestingly, node "02" has the correct font size, but the placement is wrong. Is there a way to correctly scale the axis (or groupplot) environment while preserving the labels' and nodes' font sizes as well as placing nodes at the correct position?

Best Answer

Don't specify

width=150pt,
height=150pt,

to the axis in the options. This doesn't make sense since you are controlling the dimensions from outside. Further, there is also axisratio key provided if you want different axis ratios.

\documentclass[10pt,crop]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepackage{tikzscale}
\usepackage{filecontents}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{filecontents}{font-size.tikz}
\begin{tikzpicture}[transform shape]
  \begin{axis}[
%  width=150pt,               %% don't give this
%  height=150pt,              %% don't give this
  xmin=-1,xmax=1,ymin=-1,ymax=1,
  xlabel=xlabel,
  ylabel=ylabel,
  ]
  \addplot coordinates{
  (-0.9,-0.9)
  (0.9,0.9)
  };
  \node[anchor=west] at (axis cs:-1,0) {01};
  \coordinate (a) at (axis cs:-1,0);
  \end{axis}
  \node[anchor=west,red] at (a) {02};
\end{tikzpicture}
\end{filecontents}

Some text in font size 10pt.
\input{font-size.tikz}
\includegraphics[width=250pt]{font-size.tikz}   %% use width=250pt,axisratio=2 to see the change
\end{document}

enter image description here