# Get default colored plots with “no markers” command in pgfplots

I want to plot several curves with a \foreach command in pgfplots. I don't want any markers, and I can't find a way to get colored plots without markers in a \foreach loop. Using no markers gets rid of markers and colors.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\foreach \pas in {1,2,...,10}
{
\addplot[mark=none] expression {\pas*\x};
}
\end{axis}
\end{tikzpicture}
\end{document}

-
add comment

## 2 Answers

If you just supply the option[mark=none], you reset the other options for the plot, resulting in black, solid lines. You should use a plus sign (\addplot +[mark=none] ...) to append the mark=none option while leaving the other options untouched.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\foreach \pas in {1,2,...,10}
{
\addplot +[mark=none] expression {\pas*\x};
}
\end{axis}
\end{tikzpicture}
\end{document}


Note that if you don't want any plot marks in any of your plots, you could also set the axis option no markers to switch the marks off for all plots.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{axis}[no markers]
\foreach \pas in {1,2,...,10}
{
\addplot expression {\pas*\x};
}
\end{axis}
\end{tikzpicture}
\end{document}

-
thanks Jake. I didn't find it in the manual. That makes complete sense ! –  ben paillard Aug 6 '11 at 10:02
Glad it helps! It's on p. 24 of the PGFplots manual. –  Jake Aug 6 '11 at 10:17
add comment

Although this solution works it is not recommended. See Jake's comment and solution instead).

If you use \pgfsetplotmarksize{0pt} then you still get the colored lines but the no mark. I am not sure why mark=none resulted in no colors.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}{% begin group to keep settings local
\pgfsetplotmarksize{0pt}
\begin{tikzpicture}% no markers here
\begin{axis}
\foreach \pas in {1,2,...,10} {
\addplot  expression {\pas*\x};
}
\end{axis}
\end{tikzpicture}
}% end group
%
\begin{tikzpicture}% this will have markers
\begin{axis}
\foreach \pas in {1,2,...,10} {
\addplot  expression {\pas*\x};
}
\end{axis}
\end{tikzpicture}
\end{document}

-
the thing is I wanted to have markers on other part of my document, so i tried 'marker size = 0pt' in addplot's options, which resulted in black lines as well... then I tried it in the axis' options, which worked ! Then i tried 'no markers' in axis' options which worked as well. So 'mark=none' results in no color in addplot's option ! –  ben paillard Aug 5 '11 at 18:37
I tried all those options as well, and perhaps some other experts can explain why they don't work, or if that is a bug. To have markers in other parts of your doc, you can either reset \pgfsetplotmarksize{}, or use grouping as the updated MWE shows. –  Peter Grill Aug 5 '11 at 18:42
I found the issue. addplot must not have any option, and no markers must be declared as axis' option. if you declare anything in addplot option like smooth or whatever it will turn line colors to black –  ben paillard Aug 5 '11 at 18:55
Still seems like a bug to me, but this workaround should work for you. –  Peter Grill Aug 5 '11 at 19:46
This is not a bug, the behaviour is correct and documented in the manual. Just setting one option for a plot resets all other styles. If you want to append an option, use +[<option>]. I would suggest deleting this answer. –  Jake Aug 6 '11 at 2:02
show 1 more comment