[Tex/LaTex] Pre-defined color cycles à la RColorBrewer

colorpgfplots

When I have multiple line plots in pgfplots, the colors of the lines cycle through a few colors (my guess is the colors are blue, red, black and dark khaki) before repeating with different marks. See below:

enter image description here

However, in my opinion these default colors are not very nice. For example, compare the colors used by Color Brewer for qualitative data.

Based on the following link, I know enough about how to define my own line color styles in pgfplots. For example,

\definecolor{s1}{RGB}{228, 26, 28}
\definecolor{s2}{RGB}{55, 126, 184}
\definecolor{s3}{RGB}{77, 175, 74}
\definecolor{s4}{RGB}{152, 78, 163}
\definecolor{s5}{RGB}{255, 127, 0}
\pgfplotscreateplotcyclelist{set1}{
    s1,every mark/.append style={fill=s1},mark=*\\
    s2,every mark/.append style={fill=s2},mark=*\\
    s3,every mark/.append style={fill=s3},mark=*\\
    s4,every mark/.append style={fill=s4},mark=*\\
    s5,every mark/.append style={fill=s5},mark=*\\
}

Before defining my own color schemes, I was wondering if someone had already done this as a LaTeX/pgfplots package? If not, would this be a useful feature that could be incorporated in a future version of pgfplots?

Best Answer

This is an edit of Stefan Pinnow:

Jake is referring to a non-PGFPlots/external colorbrewer library of (I guess LoopSpace). For the PGFPlots/internal colorbrewer library please have a look at my answer.


There is now a PGFPlots library colorbrewer that creates cycle lists using the colorbrewer color schemes. The color values are taken from the ColorBrewer Excel file.

To set a colorbrewer cycle list, you call colorbrewer cycle list=<scheme>, which will define the necessary colors (colorbrewer1 to colorbrewer8) and create a cycle list called colorbrewer.

The number of colors and plot styles that are defined can be set using the key colorbrewer values=<number>.

\documentclass{article}
\usepackage{pgfplots}   
\usepgfplotslibrary{colorbrewer}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    colorbrewer cycle list=Dark2
]
\addplot {rnd};
\addplot {rnd-1};
\addplot {rnd-2};
\addplot {rnd-3};
\addplot {rnd-4};
\addplot {rnd-5};
\addplot {rnd-6};
\addplot {rnd-7};
\end{axis}
\end{tikzpicture}

\end{document}  

Here's an overview of the color schemes:

Related Question