如何修改 latex 代码以具有双 y 轴

如何修改 latex 代码以具有双 y 轴

我正在尝试在所有子图的两侧添加 2 个 y 轴,并绘制一条将其与蓝色条形图连接起来的趋势线。不幸的是,我不知道该怎么做。

代码:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns,pgfplots.groupplots}
\pgfplotsset{
    compat=1.17,
    selective show sum on top/.style={
        /pgfplots/scatter/@post marker code/.append code={
            \ifnum\coordindex=#1
                \node[
                    at={(normalized axis cs:
                        \pgfkeysvalueof{/data point/x},
                        \pgfkeysvalueof{/data point/y})
                    },
                    anchor=south,
                ]
                {\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}};
            \fi
        },
    },
    selective show sum on top/.default=0
}

\begin{document}
\begin{tikzpicture}

    \begin{groupplot}[
        group style={group size=4 by 3, vertical sep=1.5cm},
        width=5.5cm, height=6cm,
        ybar stacked, ymin=0,
        %bar width=15pt,
        symbolic x coords={125,250,500,1000,2000},
        xtick=data,
        legend style={at={(0.3,1.20)}, anchor=west, legend columns=4}, 
        label style = {font=\normalsize},
        nodes near coords,
        ylabel={Y-Axis Label Placeholder},
    ]
    
    % First Chart
    \nextgroupplot[xlabel={X-Axis Label 1}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Second Chart
    \nextgroupplot[xlabel={X-Axis Label 2}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Third Chart
    \nextgroupplot[xlabel={X-Axis Label 3}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Fourth Chart
    \nextgroupplot[xlabel={X-Axis Label 4}, legend to name=grouplegend]
   \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};
    \legend{PIM Kernel,Inter-PIM Core, CPU-DPU, DPU-CPU}

    \nextgroupplot[xlabel={X-Axis Label 1}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Second Chart
    \nextgroupplot[xlabel={X-Axis Label 2}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Third Chart
    \nextgroupplot[xlabel={X-Axis Label 3}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Fourth Chart
    \nextgroupplot[xlabel={X-Axis Label 4}, legend to name=grouplegend]
   \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};
    \legend{PIM Kernel,Inter-PIM Core, CPU-DPU, DPU-CPU}


    \nextgroupplot[xlabel={X-Axis Label 1}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

  

    % Second Chart
    \nextgroupplot[xlabel={X-Axis Label 2}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Third Chart
    \nextgroupplot[xlabel={X-Axis Label 3}]
    \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};

    % Fourth Chart
    \nextgroupplot[xlabel={X-Axis Label 4}, legend to name=grouplegend]
   \addplot [pattern=crosshatch dots, pattern color=blue, selective show sum on top] coordinates {
        (125,1) (250,0) (500,1) (1000,1) (2000,1)};
    \addplot [pattern=horizontal lines, pattern color=red] coordinates {
        (125,0) (250,3) (500,3) (1000,4) (2000,1)};
    \addplot [pattern=north west lines, pattern color=olive, selective show sum on top/.list={0,1,2}] coordinates {
        (125,0) (250,1) (500,4) (1000,4) (2000,1)};
    \addplot [pattern=vertical lines, pattern color=orange, selective show sum on top] coordinates {
        (125,0) (250,0) (500,0) (1000,0) (2000,2)};
    %\legend{PIM Kernel,Inter-PIM Core, CPU-DPU, DPU-CPU}
    

    \end{groupplot}

    % Placing the legend
    \node at ($(group c4r1.south) - (7.5,13.5cm)$) [anchor=north] {\ref{grouplegend}};

    % Adding sub-captions
    % Adding sub-captions
\node at ($(group c1r1.south) - (0,1.0cm)$) [anchor=north] {(a) Sub-caption for Chart 1};
\node at ($(group c2r1.south) - (0,1.0cm)$) [anchor=north] {(b) Sub-caption for Chart 2};
\node at ($(group c3r1.south) - (0,1.0cm)$) [anchor=north] {(c) Sub-caption for Chart 3};
\node at ($(group c4r1.south) - (0,1.0cm)$) [anchor=north] {(d) Sub-caption for Chart 4};
\node at ($(group c1r2.south) - (0,1.0cm)$) [anchor=north] {(e) Sub-caption for Chart 5};
\node at ($(group c2r2.south) - (0,1.0cm)$) [anchor=north] {(f) Sub-caption for Chart 6};
\node at ($(group c3r2.south) - (0,1.0cm)$) [anchor=north] {(g) Sub-caption for Chart 7};
\node at ($(group c4r2.south) - (0,1.0cm)$) [anchor=north] {(h) Sub-caption for Chart 8};
\node at ($(group c1r3.south) - (0,1.0cm)$) [anchor=north] {(i) Sub-caption for Chart 9};
\node at ($(group c2r3.south) - (0,1.0cm)$) [anchor=north] {(j) Sub-caption for Chart 10};
\node at ($(group c3r3.south) - (0,1.0cm)$) [anchor=north] {(k) Sub-caption for Chart 11};
\node at ($(group c4r3.south) - (0,1.0cm)$) [anchor=north] {(l) Sub-caption for Chart 12};


\end{tikzpicture}
\end{document}

输出: 在此处输入图片描述

有人能帮我在另一边添加另一个 y 轴吗?

谢谢您的帮助!

相关内容