6

I'm using pgfplots to plot multiple lines, but after a certain number of lines, they seem to revert to dashed lines regardless of line style.

enter image description here

Is there a way to fix this? The code to generate the figure is attached:

\documentclass[10pt]{article}

\usepackage{pgfplots}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}
\addplot+[color=magenta,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
\addplot+[color=magenta,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
\addplot+[color=black,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
\addplot+[color=black,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
\addplot+[color=red,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
\addplot+[color=red,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};

\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

2 Answers 2

7

mark options only affects the marks - not the style of the lines. \addplot+ adds options to those which would be used by \addplot, which would default to cycling through line styles, colours etc. So only options you explicitly override don't take effect. If you don't want the options to be appended, use \addplot[<options>] instead. For example:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}
\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot[color=magenta,mark=*,semithick, mark options={solid,fill=markercolor}]
    coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
    \addplot[color=magenta,mark=square*,semithick, mark options={solid,fill=markercolor}]
    coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
    \addplot[color=black,mark=*,semithick, mark options={solid,fill=markercolor}]
    coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
    \addplot[color=black,mark=square*,semithick, mark options={solid,fill=markercolor}]
    coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
    \addplot[color=red,mark=*,semithick, mark options={solid,fill=markercolor}]
    coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
    \addplot[color=red,mark=square*,semithick, mark options={solid,fill=markercolor}]
    coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};
  \end{axis}
\end{tikzpicture}
\end{document}

gives

solid lines

Or, for the same result with less hassle:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{pgfplots}
\pgfplotsset{%
  compat=1.13,
  every axis plot/.append style={semithick, mark options={solid,fill=markercolor}}
}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}
\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot [color=magenta ,mark=*]
    coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
    \addplot [color=magenta, mark=square*]
    coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
    \addplot [color=black, mark=*]
    coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
    \addplot [color=black, mark=square*]
    coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
    \addplot [color=red, mark=*]
    coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
    \addplot [color=red, mark=square*]
    coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};
  \end{axis}
\end{tikzpicture}
\end{document}
0
3

You've gotten a good answer already, so this is just an alternative approach, which may be useful in other contexts. pgfplots has a list of styles that it steps through for each \addplot. There are several lists to choose from, see section 4.7.7 Cycle Lists – Options Controlling Line Styles in the manual, but you can also define your own. This is especially useful if you have multiple figures and you want the same linestyles etc. in all of them.

To select a cycle list as it's called, use cycle list name=<name of list>. You can do this for a single axis or put it in \pgfplotsset to set it 'globally'. To create a new list use \pgfplotscreateplotcyclelist{<name>}{<list>}. In the list, put one set of options on each line, and end the line with \\, as in the example below.

\documentclass[border=4mm]{standalone}

\usepackage{pgfplots}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}

\pgfplotscreateplotcyclelist{JessePlots}{%
color=magenta,mark=*,semithick, mark options={solid,fill=markercolor}\\
color=magenta,mark=square*,semithick, mark options={solid,fill=markercolor}\\
color=black,mark=*,semithick, mark options={solid,fill=markercolor}\\
color=black,mark=square*,semithick, mark options={solid,fill=markercolor}\\
color=red,mark=*,semithick, mark options={solid,fill=markercolor}\\
color=red,mark=square*,semithick, mark options={solid,fill=markercolor}\\
}
% \pgfplotsset{cycle list name=JessePlots} % for setting the cycle list globally
\begin{document}

\begin{tikzpicture}
\begin{axis}[cycle list name=JessePlots]
\addplot coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
\addplot coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
\addplot coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
\addplot coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
\addplot coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
\addplot coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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