0

I use this code for plotting lines with different colors automatically

\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} 

This code produce the following :

enter image description here

But if I change the addplot command like below the lines are all black, I don't know why!

\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 Answer 1

1

You need \addplot+ instead of \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} 

enter image description here

2
  • Thank you, and maybe could you explain why ?
    – Andrea
    Commented Dec 1, 2020 at 18:02
  • 2
    @Andrea Because this is what the manual says. If you look at the bottom of p. 25 of pgfplots manual v1.17 you see the description of \addplot+ : pgfplots will append ⟨options⟩ to the automatically assigned cycle list.
    – user229669
    Commented Dec 1, 2020 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .