我最后一张组图的图例打印在最后一张组图下方,到目前为止一切顺利。但是我怎样才能像标题一样在组图上方写一段文字呢?通常,我会在不带图例图像的情况下使用图例条目,但不幸的是,这会增加第一列和第二列之间的空间。因此,我尝试在轴上设置一个节点,然后编写一个命令,但这也没有按预期工作。有人有想法吗,如何解决这个问题?
\documentclass{article}
\usepackage{pgfplots,tikz}
\pgfplotsset{
compat=1.12
}
\usetikzlibrary{patterns}
\usetikzlibrary{pgfplots.groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
height = 5cm,
width = 10cm,
group style={
group name=my plots,
group size=1 by 2,%10
},
legend cell align=left,
legend style={cells={align=left}},
legend style={draw=none},
legend style={at={(3cm,-2cm)},anchor=north,align=left,draw=white,
legend columns=4,
legend style={
/tikz/every even column /.append style={column sep=1.5cm}
},
},
legend style={/tikz/every even column/.append style={column sep=0.5cm}},
]
\nextgroupplot[ylabel={rnd}]
\addplot {rnd*6};
\nextgroupplot[ylabel={rnd}]
%1 -- spacing betwen columns breaks
% \addlegendimage{empty legend}
%\addlegendentry{\hspace{-.63cm} Some explanations to sth \dots}
%\addlegendimage{empty legend}\addlegendentry{ }
%\addlegendimage{empty legend}\addlegendentry{ }
%\addlegendimage{empty legend}\addlegendentry{ }
%2 doesn't work
%\node[below right=1cm] (T) {Hello text};
\coordinate (A) at (axis cs:-6,-6);
\node[below = 0.31cm] at (A) {Some explanations to sth \dots};
\addplot {rnd*2};
\addlegendentry{test 20134214};
\addplot {rnd*-.05};
\addlegendentry{test 2012};
\addplot {rnd*3-8};
\addlegendentry{test 201};
\addplot {rnd*6};
\addlegendentry{tes};
\end{groupplot}
\end{tikzpicture}
\end{document}
答案1
我有点搞不清楚你到底想做什么。要在组图上方添加描述,最简单的方法是title=..
在第一个选项中使用\nextgroupplot
。
如果要在图例上方放置描述,可以为其命名(name=..
在 中legend style
),并相对于此放置一个节点。你只需要一 legend style
, 顺便一提。
另一种方法是将节点放置在最后一个轴的位置。 ,name=my plots
因此group style
底部轴的名称是my plots c1r2
(列 1,行 2)。 因此,您可以说例如
\node [below] at (my plots c1r2.south) {The road goes ever on and on};
\documentclass{article}
\usepackage{pgfplots} %pgfplots loads tikz
\pgfplotsset{
compat=1.12
}
\usetikzlibrary{patterns,positioning}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
samples=3,
height = 5cm,
width = 10cm,
group style={
group name=my plots,
group size=1 by 2,%10
},
legend cell align=left,
legend style={
name=mylegend,
cells={align=left},
draw=none,
at={(3cm,-2cm)},anchor=north,align=left,
},
legend columns=4
]
\nextgroupplot[ylabel={rnd},title=This is awesome!]
\addplot {rnd*6};
\nextgroupplot[ylabel={rnd}]
\addplot {rnd*2};
\addlegendentry{test 20134214};
\addplot {rnd*-.05};
\addlegendentry{test 2012};
\addplot {rnd*3-8};
\addlegendentry{test 201};
\addplot {rnd*6};
\addlegendentry{tes};
\end{groupplot}
\node[above=0cm of mylegend] {Some explanations to sth \dots};
\end{tikzpicture}
\end{document}