Tikzscale 对包含三个元素的组图失败,但对包含两个元素的组图有效

Tikzscale 对包含三个元素的组图失败,但对包含两个元素的组图有效

对于自定义图形,我想将三个图形堆叠在一起,以保持可读性(多个 y 轴)和可比性(所有图形都有相同的 x 轴,第三个图形是图一和图二的组合)。为了能够正确缩放图形,我打算使用tikzscale。为了测试我的代码,我使用 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}

和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}
        ]
        \addplot [line width=1pt, color0]
        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}

但每次编译都会\nextgroupplot失败

Package pgfplots Error: Error: Plot height `-316.93126pt' is too small. This 
cannot be implemented while maintaining constant size for labels. Sorry, label 
sizes are only approximate. You will need to adjust your height..

\input如果我使用和resizebox,即不使用,它可以正常工作tikzscale,但这会损坏我的字体。如果我将堆叠图的数量减少到两个并使用,它也可以正常工作。tikzscale为什么
tikzscale 在我的案例中失败了,我该怎么做才能解决这个问题(或者我可以使用哪种不同的方法)?

答案1

这个答案并非旨在解决我的问题中的所有要点,但至少可以指出我的问题的解决方案。调整堆叠图的大小可以通过直接在 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,
    ]

并包括图中

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

尽管这需要一种更间接的方法,但至少可以实现扩展。

相关内容