# Tikzscale fails for group plot with three elements, but works for two elements

For a custom figure I wanted to stack three figures on top of each other, to keep readability (multiple y axis) and comparability (all figures have the same x axis, the third figure is a combination of figure one and two). To be able to scale the figure properly I intended to use tikzscale. To test my code I wrote a small test sample, with main.tex:

\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}
%\usetikzlibrary{external}
\usepackage{letltxmacro}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{tikzscale}
\usepackage{siunitx}
\usepackage{subcaption}
%\tikzexternalize[prefix=tikz-cache/]
%\tikzset{external/force remake}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat=1.17}

\begin{document}
\begin{figure}[htpb]
\centering
\includegraphics[width=.8\linewidth, height=1.2\linewidth]{stacked_test_simple.tikz}
%\resizebox{.8\linewidth}{1.2\linewidth}{\input{stacked_test_simple.tikz}}
\caption{Image II}
\end{figure}
\end{document}


and stacked_test_simple.tikz:

\usepgfplotslibrary{groupplots}
\begin{tikzpicture}

\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\definecolor{color1}{rgb}{1,0.498039215686275,0.0549019607843137}

\begin{groupplot}[
group style={
% set how the plots should be organized
group size=1 by 3,
% only show ticklabels and axis labels on the bottom
x descriptions at=edge bottom,
% set the vertical sep' to zero
vertical sep=0pt,
},
]
% start the first plot
\nextgroupplot[
tick align=outside,
tick pos=left,
x grid style={white!69.0196078431373!black},
xmajorgrids,
xmin=1, xmax=5,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
y label style={color=color0},
yticklabel style={color=color0},
xmajorticks=false,
ylabel={Plot 1},
ymajorgrids,
ymin=0, ymax = 26,
ytick style={color=black}
]
table {%
1 1
2 4
3 9
4 16
5 25
};
\nextgroupplot[
tick align=outside,
tick pos=left,
x grid style={white!69.0196078431373!black},
ytick style={color=color0},
xmajorgrids,
xmajorticks=false,
xmin=1, xmax=5,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
y label style = {color=color0},
yticklabel style={color=color0},
ylabel={Plot 2},
ymajorgrids,
ymin = -6, ymax = 0,
ytick style={color=black}
]
\addplot [semithick, color0, mark=square*, mark size=2, mark options={solid}, only marks]
table {%
1 -1
2 -2
3 -3
4 -4
5 -5
};
\nextgroupplot[tick align=outside,
tick pos=left,
x grid style={white!69.0196078431373!black},
xlabel={X data},
xmajorgrids,
xmin=1, xmax=5,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
ylabel style={color=color0},
ylabel={Plot 3},
ymajorgrids,
ymin = 0, ymax = 6,
ytick style={color=black},
yticklabel style={color=color0}
]
\addplot [semithick, color0, mark=square*, mark size=2, mark options={solid}, only marks]
table {%
1 1
2 2
3 3
4 4
5 5
};
\end{groupplot}
\end{tikzpicture}


but compilation fails for each \nextgroupplot with

Package pgfplots Error: Error: Plot height -316.93126pt' is too small. This
cannot be implemented while maintaining constant size for labels. Sorry, label


It works fine if I use \input and resizebox, i.e. without tikzscale, but that will damage my fonts. It also works fine if I reduce the amount of stacked plots to two and use tikzscale.
Why is tikzscale failing for my case, and what can I do to fix that issue (or what kind of different approach could I use)?

This answer is not indended to address all points in my question, but at least to point out a solution to my issues. Resizing the stacked plot worked by including the targeted size directly in the groupplot-definition:

\begin{groupplot}[
group style={
% set how the plots should be organized
group size=1 by 3,
% only show ticklabels and axis labels on the bottom
x descriptions at=edge bottom,
% set the vertical sep' to zero
vertical sep=0pt,
},
heigth=0.4\linewidth,
width=0.8\linewidth,
]


and including the figure with

\includegraphics[width=\linewidth]{stacked_test_simple.tikz}
`

This allows at least scaling, even though it requires a more indirect approach.