14

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}

2 Answers2

16

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}
Jake
  • 232,450
0

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}
Peter Grill
  • 223,288
  • 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 05 '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 05 '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 05 '11 at 18:55
  • Still seems like a bug to me, but this workaround should work for you. – Peter Grill Aug 05 '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 06 '11 at 02:02
  • I've added warning at the top of this solution so that it is there and people know not to do that. If you still think it is better to delete this all together that is fine with me. – Peter Grill Aug 06 '11 at 02:52