我正在尝试groupplot
使用 PGFPlots 创建一个,其中每个子图都使用colorbrewer
库中的颜色。添加时,\pgfplotsset{cycle/list/Set1-5}
两个子图未对齐,我收到错误消息:
Package pgf Error: No shape named is known.
See the pgf package documentation for explanation.
Type H <return> for immediate help.
...
l.22 \addplot
coordinates {(0,2) (1,1) (2,0)};
我尝试了几种不同的方法,例如直接cycle list/Set1-5
将作为选项添加\nextgroupplot
,但结果相同。我也尝试了不同的颜色图,但结果相同。如果我只将 colorbrewer 添加到第一个图中,它可以正常工作,但当我将它添加到第二个图中时,我收到此错误。图中的颜色显示正确,但子图未对齐。
未对齐的子图colorbrewer
:
对齐子图,无colorbrewer
:
梅威瑟:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{tikz}
% I guess that I only need one of these
\usepgfplotslibrary{groupplots,colorbrewer}
\usetikzlibrary{pgfplots.colorbrewer}
\begin{document}
% Line that causes the error
\pgfplotsset{/pgfplots/group/every plot/.append style = {%
cycle list/Set1-5}}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2},height=3cm,width=3cm]
\nextgroupplot
\addplot coordinates {(0,0) (1,1) (2,2)};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (2,0)};
\end{groupplot}
\end{tikzpicture}
\end{document}
谢谢你的帮助!
答案1
当您想使用不同的循环列表进行绘图时,仅添加cycle list/...
选项\nextgroupplot
是行不通的。(不确定这是否是一个错误。)但您可以提前初始化所有需要/想要的颜色图,然后只需在上述选项中激活相应的循环列表即可……
% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{
colorbrewer,
groupplots,
}
\pgfplotsset{
compat=1.14,
% initialize colormaps that you want to use later
% (either in colormaps or as cycle lists)
colormap/Set1-5,
colormap/Set2-5,
}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=1 by 2,
},
height=3cm,
width=3cm,
]
\nextgroupplot[
% activate cycle list you want to use
cycle list name=Set1-5,
]
\addplot coordinates {(0,0) (1,1) (2,2)};
\nextgroupplot[
cycle list name=Set2-5,
]
\addplot coordinates {(0,2) (1,1) (2,0)};
\end{groupplot}
\end{tikzpicture}
\end{document}