PGFplots 多个 ylabel

PGFplots 多个 ylabel

我想在组图中有多个 y 标签。现在我有 4 个不同的 y 标签值:Range1Range2和。我想添加一个通用的 y 标签Range3Range4比如“吞吐量”。我该怎么做?

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}
    \begin{groupplot}[group style={group size= 2 by 4},height=5cm,width=6.4cm]
        \nextgroupplot[title=type1,ylabel={Range1 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
        \nextgroupplot[title=type2,symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
        \nextgroupplot[ylabel={Range2 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
        \nextgroupplot[symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
        \nextgroupplot[ylabel={Range3 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
        \nextgroupplot[symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
        \nextgroupplot[xlabel={Number of Threads},ylabel={Range4 },symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
        \nextgroupplot[xlabel={Number of Threads},symbolic x coords={1,2,4,8,16,32,64,128},xtick=data]
                \addplot[blue] table{Data/test.dat};
    \end{groupplot}
\end{tikzpicture}

\end{document}

输出

答案1

更新:

您可以使用选项命名组group name,然后引用每个单组图:

\documentclass[margin=5mm]{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}
    \begin{groupplot}[group style={
                        group name=myplot,% <- name the group plot
                        group size= 2 by 4},height=5cm,width=6.4cm]
        \nextgroupplot[title=type1,ylabel={Range1 }]
                \addplot[blue] {x};
        \nextgroupplot[title=type2]
                \addplot[blue]{x};
        \nextgroupplot[ylabel={Range2 }]
                \addplot[blue]{x};
        \nextgroupplot
                \addplot[blue]{x};
        \nextgroupplot[ylabel={Range3 }]
                \addplot[blue]{x};
        \nextgroupplot
                \addplot[blue]{x};
        \nextgroupplot[xlabel={Number of Threads},ylabel={Range4 }]
                \addplot[blue]{x};
        \nextgroupplot[xlabel={Number of Threads}]
                \addplot[blue]{x};
    \end{groupplot}
    \path (myplot c1r1.outer north west)% plot in column 1 row 1
          -- node[anchor=south,rotate=90] {throughput}% label midway
          (myplot c1r4.outer south west)% plot in column 1 row 4
    ;
\end{tikzpicture}

\end{document}

在此处输入图片描述


原始答案:

您可以在第一个图的顶部定义一个坐标,在最后一个图的底部定义一个坐标。然后,您可以将标签垂直放置在这两个坐标之间的左边界上current bounding box

\documentclass[margin=5mm]{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}
    \begin{groupplot}[group style={group size= 2 by 4},height=5cm,width=6.4cm]
        \nextgroupplot[title=type1,ylabel={Range1 }]
                \addplot[blue] {x};
                \coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
        \nextgroupplot[title=type2]
                \addplot[blue]{x};
        \nextgroupplot[ylabel={Range2 }]
                \addplot[blue]{x};
        \nextgroupplot
                \addplot[blue]{x};
        \nextgroupplot[ylabel={Range3 }]
                \addplot[blue]{x};
        \nextgroupplot
                \addplot[blue]{x};
        \nextgroupplot[xlabel={Number of Threads},ylabel={Range4 }]
                \addplot[blue]{x};
        \nextgroupplot[xlabel={Number of Threads}]
                \addplot[blue]{x};
                \coordinate (bot) at (rel axis cs:0,0);% coordinate at bottom of the last plot
    \end{groupplot}
    \path (top-|current bounding box.west)-- 
          node[anchor=south,rotate=90] {throughput} 
          (bot-|current bounding box.west);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容