2

What I have: A plot in which I want to assign a specific color of colorbrewer scheme "Set1" to a plot curve (instead of using them in their 'line of order'). This means the curve of "Simulation 1" should be red and the curve for "Simulation 2" should be purple. The color in question can be adressed as Set1-4-4 (or Set1-8-4, ect.) in the Brewer colors. However, I seem to have an error in the syntax, as shown in a MWE below.

It does give the desired outcome, if I work around with \definecolor and the brewers RGB colors shown here, but I suppose there should be a better way?

What I read: Default color pgfplot, Pre-defined color cycles à la RColorBrewer?

The code

\documentclass[]{standalone}
\usepackage{tikz} 
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{cycle list/Set1}
\definecolor{c4}{RGB}{152,78,163}
\pgfplotsset{compat=1.13}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
cycle list name=Set1,
]
\addplot+[thick] {1/x};
\addplot+[very thick, loosely dotted] {1/x};
%\addplot+[very thick, loosely dotted, c4] {1/x}; %working
%\addplot+[very thick, loosely dotted, purple] {1/x}; %not working
%\addplot+[very thick, loosely dotted, color=Set1-4-4] {1/x};  %not working

\legend{
    {Simulation 1}, 
    {Simulation 2},
};
\end{axis}
\end{tikzpicture} 
\end{document}

1 Answer 1

6

Following Fill pgfplot bars with colorbrewer, you can use index of colormap as key in the plot definition. You also need to select the color scheme you want, including the subscheme (here: Set1-4). In the axis definition you don't need to indicate anything in this specific case.

MWE:

\documentclass[]{standalone}
\usepackage{tikz} 
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{cycle list/Set1-4}
\pgfplotsset{compat=1.13}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[thick] {1/x};
\addplot+[very thick, dashed, index of colormap=4 of Set1-4] {1/x};

\legend{
    {Simulation 1}, 
    {Simulation 2},
};
\end{axis}
\end{tikzpicture} 
\end{document}

Result:

enter image description here

You must log in to answer this question.

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