如何自动为同一绘图上的不同线条设置不同的颜色

如何自动为同一绘图上的不同线条设置不同的颜色

我使用此代码自动绘制不同颜色的线条

\documentclass[crop]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps} 
\pgfplotsset{compat=1.9}
\pgfplotsset{
colormap={bright}{rgb255=(0,0,0) rgb255=(78,3,100) rgb255=(2,74,255)
    rgb255=(255,21,181) rgb255=(255,113,26) rgb255=(147,213,114) rgb255=(230,255,0)
    rgb255=(255,255,255)}
}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
colormap name=bright, % activate the defined colormap
cycle list={[of colormap]},
every axis plot/.append style={mark=none,ultra thick} % set options for all plots
]
\addplot {x};
\addplot {x+1};
\addplot {x+2};
\addplot {x+3};
\addplot {x+4};
\addplot {x+5};
\addplot {x+6};
\addplot {x+7}; 
\end{axis}
\end{tikzpicture}

\end{document} 

该代码产生以下内容:

在此处输入图片描述

但是如果我像下面这样更改 addplot 命令,那么所有线条都会变成黑色,我不知道为什么!

\addplot [domain=0:10] {x};
\addplot [domain=0:10] {x+1};
\addplot [domain=0:10] {x+2};
\addplot [domain=0:10] {x+3};
\addplot [domain=0:10] {x+4};
\addplot [domain=0:10] {x+5};
\addplot [domain=0:10] {x+6};
\addplot [domain=0:10] {x+7}; 

答案1

您需要的\addplot+不是\addplot

\documentclass[crop]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps} 
\pgfplotsset{compat=1.9}
\pgfplotsset{
colormap={bright}{rgb255=(0,0,0) rgb255=(78,3,100) rgb255=(2,74,255)
    rgb255=(255,21,181) rgb255=(255,113,26) rgb255=(147,213,114) rgb255=(230,255,0)
    rgb255=(255,255,255)}
}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
colormap name=bright, % activate the defined colormap
cycle list={[of colormap]},
every axis plot/.append style={mark=none,ultra thick} % set options for all plots
]
\addplot+[domain=0:10] {x};
\addplot+[domain=0:10] {x+1};
\addplot+[domain=0:10] {x+2};
\addplot+[domain=0:10] {x+3};
\addplot+[domain=0:10] {x+4};
\addplot+[domain=0:10] {x+5};
\addplot+[domain=0:10] {x+6};
\addplot+[domain=0:10] {x+7}; 
\end{axis}
\end{tikzpicture}
\end{document} 

在此处输入图片描述

相关内容