1

I am trying to define some color cycle lists based on a corporate design. Therefore they should be selectable by the user at a later point. Definitions should be available for bar, pie and regular line plots. Everything works fine for line plots, but I am struggling with the definitions for bar plots. This is where I am currently in my MWE and I don't know why I get black bordered bars only:

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{/pgfplots/bar cycle list/.style={/pgfplots/cycle list={
            {blue,fill=blue!30!white,mark=none},
            {red,fill=red!30!white,mark=none},
            {brown!60!black,fill=brown!30!white,mark=none},
            {black,fill=gray,mark=none},},},}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[ybar,enlargelimits=0.15]
    \addplot[] coordinates{(5,10) (10,15) (15,5) (20,24) (25,30)};
    \addplot[] coordinates{(5,3) (10,5) (15,15) (20,20) (25,35)};
    \end{axis}
    \end{tikzpicture}
\end{document}

The result looks like this:

enter image description here

How can I achieve the coloring of the bars according to defined cycle list?

Also is there a similar option like \pgfplotscreate<bar>plotcyclelist that can be used to store a named list and load it later through \pgfplotsset{<bar> cycle list name=}?

1 Answer 1

1

The pgfplots manual (v1.17 (2020/02/29), page 214) notes the following:

Thus, the currently active cycle list will be used if you write either \addplot+[〈keys〉] ...; or if you don't use square brackets as in \addplot[〈explicit plot specification〉]...;

Although the explanation is not very clear, this implies that you should remove the square brackets, as they overwrite the currently active cycle list:

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{/pgfplots/bar cycle list/.style={/pgfplots/cycle list={
            {blue,fill=blue!30!white,mark=none},
            {red,fill=red!30!white,mark=none},
            {brown!60!black,fill=brown!30!white,mark=none},
            {black,fill=gray,mark=none},},},}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[ybar,enlargelimits=0.15]
    \addplot coordinates{(5,10) (10,15) (15,5) (20,24) (25,30)};
    \addplot coordinates{(5,3) (10,5) (15,15) (20,20) (25,35)};
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

The list can also be stored first and then used by a bar plot later. Storing a list is done using the command \pgfplotscreateplotcyclelist{listname}{list specification}, which can be used with the axis option cycle list name.

MWE (result is the same as above):

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotscreateplotcyclelist{customlist}{
             {blue,fill=blue!30!white,mark=none},
             {red,fill=green!30!white,mark=none},
             {brown!60!black,fill=brown!30!white,mark=none},
             {black,fill=gray,mark=none}
}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[ybar,enlargelimits=0.15,cycle list name=customlist]
    \addplot coordinates{(5,10) (10,15) (15,5) (20,24) (25,30)};
    \addplot coordinates{(5,3) (10,5) (15,15) (20,20) (25,35)};
    \end{axis}
    \end{tikzpicture}
\end{document}

If you want to use a custom list by name in pgfplotsset then you need the syntax /pgfplots/bar cycle list/.style={/pgfplots/cycle list name={listname}}. This setting will remain in effect until a new list is loaded, without needing to specify it as an option for individual plots.

MWE:

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotscreateplotcyclelist{customlist}{
             {blue,fill=blue!30!white,mark=none},
             {orange,fill=orange!30!white,mark=none},
             {brown!60!black,fill=brown!30!white,mark=none},
             {black,fill=gray,mark=none}
}

\pgfplotscreateplotcyclelist{otherlist}{
             {blue,fill=blue!30!white,mark=none},
             {green,fill=green!30!white,mark=none},
             {brown!60!black,fill=brown!30!white,mark=none},
             {black,fill=gray,mark=none}
}

\pgfplotsset{/pgfplots/bar cycle list/.style={/pgfplots/cycle list name={otherlist}}}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[ybar,enlargelimits=0.15]
    \addplot coordinates{(5,10) (10,15) (15,5) (20,24) (25,30)};
    \addplot coordinates{(5,3) (10,5) (15,15) (20,20) (25,35)};
    \end{axis}
    \end{tikzpicture}

    \begin{tikzpicture}
    \begin{axis}[ybar,enlargelimits=0.15]
    \addplot coordinates{(5,10) (10,15) (15,5) (20,24) (25,30)};
    \addplot coordinates{(5,3) (10,5) (15,15) (20,20) (25,35)};
    \end{axis}
    \end{tikzpicture}
    
\pgfplotsset{/pgfplots/bar cycle list/.style={/pgfplots/cycle list name={customlist}}}

    \begin{tikzpicture}
    \begin{axis}[ybar,enlargelimits=0.15]
    \addplot coordinates{(5,10) (10,15) (15,5) (20,24) (25,30)};
    \addplot coordinates{(5,3) (10,5) (15,15) (20,20) (25,35)};
    \end{axis}
    \end{tikzpicture} 

\end{document}

Result:

enter image description here

7
  • Thanks Marijn, I think I didn't use PGFplots often enough lately, to overlook this. ;-) Is there also an option to store a cycle list and load it later?
    – TobiBS
    Jul 23, 2020 at 10:24
  • @TobiBS for that you can use \pgfplotscreateplotcyclelist{somelist} with \begin{axis}[cycle list name=somelist], see page 219 of the manual.
    – Marijn
    Jul 23, 2020 at 18:14
  • This is what I referred to in my question already, but how do I make a bar plot take these colors? In the end they are stored in a bar cycle list, hence how do I store a list in this space?
    – TobiBS
    Jul 23, 2020 at 18:28
  • @TobiBS I've added an example to my answer. Is this what you mean, and if not, what exactly are you looking for?
    – Marijn
    Jul 24, 2020 at 7:22
  • 1
    @TobiBS I've added another edit for using the name in pgfplotsset, is that what you are looking for?
    – Marijn
    Jul 24, 2020 at 9:12

You must log in to answer this question.

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