[Tex/LaTex] Despite using the ‘no markers’ option, I still get plotmarks in the legend. Why

legendpgfplots

Nice to finally post a question myself after finding solutions to my problems on numerous occasions within these forums. I hope someone can be of help (and that this hasn't been asked already).

The problem is as follows: I'm using pgfplots for the plots within my document. I used the procedure described in section 4.8.7 (Legends outside of an axis) within the pgfplots manual in order to create one legend for several horizontally aligned plots. In general this works fine. My issue is, that the marker style differs between the plot and the legend. I am using the no markers option with \addplot. The legend shows the correct line style but also markers. Is it possible to remove the markers? Did I place the ref{} command to reference the legend in the wrong place? I couldn't find any solution by browsing google or within the manual, hence my question.

The code looks as follows (I can post a minimum working example if necessary):

\begin{figure}[htb]
\centering
\begin{tikzpicture}[baseline]
\begin{axis}
[
legend columns=-1,
legend entries={$Pe_{ax} = 1$;,$Pe_{ax} = 10$;,$Pe_{ax} = 100$;,$Pe_{ax} = 1000$},
legend to name=named3,
width=6cm, height=6cm, 
xmin={0},
xmax={2},
ymin={0},
ymax={2},
xtick={0,1,2},
ytick={0,2},
xlabel= {$\Theta [-]$},
ylabel={$E(\Theta) [-]$},
label style={font=\footnotesize},
tick label style={font=\footnotesize},
legend style={draw=none}
]
\addplot+[no markers,smooth, color=black, dashed] coordinates {(1,0) (1,2)};
\addplot+[no markers,smooth, color=black, dotted] table[x=X,y=Y1] {Tabellen/Butt_1999_Bo1.txt};
\addplot+[no markers,smooth, color=black, dashdotdotted] table[x=X,y=Y1] {Tabellen/Butt_1999_Bo10.txt};
\addplot+[no markers,smooth, color=black, dashdotted] table[x=X,y=Y1] {Tabellen/Butt_1999_Bo100.txt};
\addplot+[no markers,smooth, color=black, solid] table[x=X,y=Y1] {Tabellen/Butt_1999_Bo1000.txt};
\end{axis}
\end{tikzpicture}
\hspace{0cm}
\centering
\begin{tikzpicture}[baseline]
\begin{axis}
[
width=6cm, height=6cm, 
xmin={0},
xmax={2},
ymin={0},
ymax={1},
xtick={0,1,2},
ytick={0,1},
xlabel= {$\Theta [-]$},
ylabel={$F(\Theta) [-]$},
label style={font=\footnotesize},
tick label style={font=\footnotesize}
]
\addplot+[no markers,smooth, color=black, dashed] coordinates {(1,0) (1,1)};
\addplot+[no markers,smooth, color=black, dotted] table[x=X,y=Y2] {Tabellen/Butt_1999_Bo1.txt};
\addplot+[no markers,smooth, color=black, dashdotdotted] table[x=X,y=Y2] {Tabellen/Butt_1999_Bo10.txt};
\addplot+[no markers,smooth, color=black, dashdotted] table[x=X,y=Y2] {Tabellen/Butt_1999_Bo100.txt};
\addplot+[no markers,smooth, color=black, solid] table[x=X,y=Y2] {Tabellen/Butt_1999_Bo1000.txt};
\end{axis}
\end{tikzpicture}
\ref{named3}
\caption{Text.}
\end{figure}

Hope this helps! Thanks in advance for any ideas, thoughts and the like!

Edit: as requested here is a minimum working example of the problem.

\documentclass[12pt,a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[htb]
\centering
\pgfplotsset{domain=-1:1}
\begin{tikzpicture}[baseline]
\begin{axis}
[
legend columns=-1,
legend entries={$x^2$;,$x^3$;,$x^4$;,$x^5$},
legend to name=named,
width=6cm, height=6cm, 
xlabel= {$x$},
ylabel={$f(x)$},
legend style={draw=none}
]
\addplot+[no markers,smooth, color=black, dashed]{x^2};
\addplot+[no markers,smooth, color=black, solid] {x^3};
\addplot+[no markers,smooth, color=black, dashdotdotted] {x^4};
\addplot+[no markers,smooth, color=black, dashdotted] {x^5};
\end{axis}
\end{tikzpicture}
\hspace{0cm}
\centering
\begin{tikzpicture}[baseline]
\begin{axis}
[
width=6cm, height=6cm, 
xlabel= {$x$},
ylabel={$f'(x)$},
]
\addplot+[no markers,smooth, color=black, dashed]{2*x};
\addplot+[no markers,smooth, color=black, solid] {3*x^2};
\addplot+[no markers,smooth, color=black, dashdotdotted] {4*x^3};
\addplot+[no markers,smooth, color=black, dashdotted] {5*x^4};
\end{axis}
\end{tikzpicture}
\ref{named}
\caption{Minimum working example.}
\end{figure}
\end{document}

Best Answer

Note: I'm assuming you're using pgfplots v1.8.

You're passing the no markers option to \addplot+, but no markers is an option available for the axis environment, not for \addplot commands. That's likely the problem.

no markers (assuming it is passed to axis) does exactly what you want, i.e. disable all plotmarks on all the graphs within that axis environment; Torbjørn T.'s comment is sound.

\begin{axis}[no markers,...]
\addplot+[...] ... ;
...
\end{axis}

To disable markers on a given \addplot (or \addplot+), you can pass the mark=none option to that command.

\begin{axis}[...]
\addplot+[mark=none,...] ... ;
...
\end{axis}

However, neither

\addplot+[no markers,...] ... ;

nor

\begin{axis}[mark=none,...]
...
\end{axis}

will produce the desired result, as your MWE demonstrates.

References:

Addendum

(following a conversation with percusse)

Revision 1.8 (2013/03/17) of the pgfplots manual also makes one reference (in the last code sample of section 5.8.1) to a no marks option for \addplot, but this option is documented nowhere in the manual. Perhaps the maintainer can shed some light on the matter if he finds this post, but for now, it's safe to assume that the no marks option has become obsolete and that it's probably best not to use it from now on.


Edit: the following code produces the desired output for me.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[htb]
\centering
\pgfplotsset{domain=-1:1}
\begin{tikzpicture}[baseline]
\begin{axis}
[
legend columns=-1,
legend entries={$x^2$;,$x^3$;,$x^4$;,$x^5$},
legend to name=named,
width=6cm, height=6cm, 
xlabel= {$x$},
ylabel={$f(x)$},
legend style={draw=none},
no markers,
]
\addplot+[smooth, color=black, dashed]{x^2};
\addplot+[smooth, color=black, solid] {x^3};
\addplot+[smooth, color=black, dashdotdotted] {x^4};
\addplot+[smooth, color=black, dashdotted] {x^5};
\end{axis}
\end{tikzpicture}
\hspace{0cm}
\centering
\begin{tikzpicture}[baseline]
\begin{axis}
[
width=6cm, height=6cm, 
xlabel= {$x$},
ylabel={$f'(x)$},
no markers,
]
\addplot+[smooth, color=black, dashed]{2*x};
\addplot+[smooth, color=black, solid] {3*x^2};
\addplot+[smooth, color=black, dashdotdotted] {4*x^3};
\addplot+[smooth, color=black, dashdotted] {5*x^4};
\end{axis}
\end{tikzpicture}
\ref{named}
\caption{Minimum working example.}
\end{figure}
\end{document}