7

I'm trying to use cycle list name = MyCyclelist in order to give my graphs all the same color/style scheme. However all lines are shown in black. I hope, somebody can help. Many thanks!

I've defined the cycle list in my header like this:

\pgfplotscreateplotcyclelist{MyCyclelist}{%
{darkgray, mark = none, thick},
{Green, mark = none, thick},
{MidnightBlue, mark = none, thick},
{Mahogany, mark = none, thick},
{RedOrange, mark = none, thick},
{RoyalPurple, mark = none, thick},
}

My pgfplot file is pretty standard:

\tikzsetnextfilename{nextfilename1}
\begin{tikzpicture}

\begin{axis}[
axis on top,
xlabel = abc,
ylabel = def,
xmin=0,
xmax=194,
ymin = 0,
legend style = {nodes=left, font =\footnotesize},
legend pos = north east,
height=0.5\textwidth,
width=\textwidth,
cycle list name=MyCyclelist
]
\pgfplotstableread{pictures/data.txt} \datatable
\addplot[legend image post style={sharp plot, line width=1pt, mark=none}, thick] table[x index = 0 , y index = 1 ] from \datatable;
\addlegendentry{abc}
\addplot[legend image post style={sharp plot, line width=1pt, mark=none}, thick] table[x index = 0 , y index = 3 ] from \datatable;
\addlegendentry{def}
    \end{axis}


\end{tikzpicture}

data.txt looks like this:

0   6.21E-11    5.40E-11    8.73E-11
1   6.04E-11    4.86E-11    8.49E-11
2   5.16E-11    5.54E-11    7.30E-11
3   6.46E-11    4.63E-11    8.12E-11
  • 3
    If there is an optional argument for the \addplot command the cycle list is not used for the plot. To change this behavior insert a + between \addplot and the optional argument: \addplot+[...]...;. – esdd Sep 17 '15 at 14:01
  • 1
    @esdd You should turn that into an answer! – darthbith Sep 19 '15 at 18:25
9

If there is no optional argument for the \addplot command a cycle list is used. This could be the default cycle list or an own list.

If there is an optional argument \addplot[<options>] the settings of the cycle list are ignored.

If you want to use both the cycle list and the optional argument you have to insert a + between the command and the optional argument: \addplot+[<options>]. In that case the options of the cycle list are set first and the options inside the optional argument are appended.

\begin{filecontents*}{data.txt}
0   6.21E-11    5.40E-11    8.73E-11
1   6.04E-11    4.86E-11    8.49E-11
2   5.16E-11    5.54E-11    7.30E-11
3   6.46E-11    4.63E-11    8.12E-11
\end{filecontents*}

\documentclass[dvipsnames]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfplotscreateplotcyclelist{MyCyclelist}{%
  {darkgray, mark = none, thick},
  {Green, mark = none, thick},
  {MidnightBlue, mark = none, thick},
  {Mahogany, mark = none, thick},
  {RedOrange, mark = none, thick},
  {RoyalPurple, mark = none, thick},
}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    axis on top,
    xlabel = abc,
    ylabel = def,
    xmin=0,
    xmax=4,%xmax=194,
    ymin = 0,
    legend style = {nodes=left, font =\footnotesize},
    legend pos = north east,
    height=0.5\textwidth,
    width=\textwidth,
    cycle list name=MyCyclelist
  ]
  \pgfplotstableread{data.txt} \datatable
  \addplot+[legend image post style={line width=1pt}] table[x index = 0 , y index = 1 ] from \datatable;
  \addlegendentry{abc}
  \addplot+[legend image post style={line width=1pt}] table[x index = 0 , y index = 3 ] from \datatable;
  \addlegendentry{def}
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here


Note: If all legend images should have the same line width you can set legend image post style={line width=1pt} as an option for the axis environment. Then you can simple use \addplot table ...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.