在此组图中,如何向单个图形添加标签。我想将每个图形标记为 (a)、(b)、(c)...
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{matrix}
\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};\label{plots:plot1}
\addplot[red] {x^2};\label{plots:plot2}
\addplot[green] {2*x};\label{plots:plot3}
\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:1,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);
% legend
\path (top|-current bounding box.north)--
coordinate(legendpos)
(bot|-current bounding box.north);
\matrix[
matrix of nodes,
anchor=south,
draw,
inner sep=0.2em,
draw
]at([yshift=1ex]legendpos)
{
\ref{plots:plot1}& curve 1&[5pt]
\ref{plots:plot2}& curve2&[5pt]
\ref{plots:plot3}& curve 3\\};
\end{tikzpicture}
\end{document}
输出:
答案1
您可以使用group names
键并借助定位library
在每个图下方添加一个节点,例如:
\node[below = 0.5cm of my plots c1r1.south] {(a)};
这里的c1r1
意思是column 1 and row 1
。
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{matrix,positioning}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group name=my plots,group size= 2 by 4,vertical sep=1.5cm },height=5cm,width=6.4cm]
\nextgroupplot[title=type1,ylabel={Range1 }]
\addplot[blue] {x};\label{plots:plot1}
\addplot[red] {x^2};\label{plots:plot2}
\addplot[green] {2*x};\label{plots:plot3}
\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:1,0);% coordinate at bottom of the last plot
\end{groupplot}
\node[below = 0.5cm of my plots c1r1.south] {(a)};
\node[below = 0.5cm of my plots c2r1.south] {(b)};
\node[below = 0.5cm of my plots c1r2.south] {(c)};
\node[below = 0.5cm of my plots c2r2.south] {(d)};
\node[below = 0.5cm of my plots c1r3.south] {(e)};
\node[below = 0.5cm of my plots c2r3.south] {(f)};
\node[below = 0.9cm of my plots c1r4.south] {(g)};
\node[below = 0.9cm of my plots c2r4.south] {(h)};
\path (top-|current bounding box.west)--
node[anchor=south,rotate=90] {throughput}
(bot-|current bounding box.west);
% legend
\path (top|-current bounding box.north)--
coordinate(legendpos)
(bot|-current bounding box.north);
\matrix[
matrix of nodes,
anchor=south,
draw,
inner sep=0.2em,
draw
]at([yshift=1ex]legendpos)
{
\ref{plots:plot1}& curve 1&[5pt]
\ref{plots:plot2}& curve2&[5pt]
\ref{plots:plot3}& curve 3\\};
\end{tikzpicture}
\end{document}
您可能需要进行调整vertical sep
以适应这些节点,就像我所做的那样(1.5 厘米)。