我使用cycle list name=exotic
它来为我的图着色。我正在寻找一种方法,要么使用数字来引用颜色(来自外来列表的索引),要么获取标记图的颜色。
以下是我尝试过的一个例子:
\pgfplotsset{cycle list name=exotic}
\begin{tikzpicture}
\begin{axis}[enlarge x limits=false]
\addplot+[thick, no marks, domain=0:360, samples=50, forget plot] {sin(x)};
\addplot+[thick, no marks, domain=0:360, samples=50] {cos(x)};
\legend{plot 1, plot 2}
\end{axis}
\end{tikzpicture}
但当然,第一个图被“遗忘”了,因此没有被考虑在颜色代码中。(即使存在更简单的解决方案,访问标记图的颜色可能也很有用。)
答案1
我将在这里给出一个如何做到这一点的一般示例。诀窍是首先定义一个colormap
,然后将其转换colormap
为一个。对于其他内容,您可以使用PGFPlots v1.13 中引入的新功能cycle list
访问的颜色。colormap
index of colormap
有关更多详细信息,请查看代码中的注释。
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.11,
%
% define a colormap that contains the colors you
% want to use in the `cycle list'
colormap={my colormap}{
color=(red)
color=(blue!50)
color=(green!50!black)
color=(orange)
},
% define some other `cycle list's to later combine them if you need
% I will use here some predefined ones for simplicity
}
% now create a `cycle list' from that colors
\pgfplotscreateplotcyclelist{my color cycle list}{
[of colormap=my colormap]
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% some options to better visualize the result
stack plots=y,
every axis plot/.style={
line width=2pt,
},
%
% define here the `cycle list' you need
cycle multiindex* list={
my color cycle list
\nextlist
[3 of]mark list
\nextlist
linestyles
\nextlist
},
]
% add some plots
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
% if you want to use the color of the 2nd plot you can do this via
% (you need index 1 here, because the index starts at 0)
\node [index of colormap=1,anchor=south]
at (0.25,2) {I am the 2nd color};
\end{axis}
\end{tikzpicture}
\end{document}