8

I want to use colorbrewer in my project since it provides color cycle lists but I struggle to use them in the right way I think. Please have a look at my MWE:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{cycle list/Dark2-8}

\begin{document}

\begin{figure}[h!]
    \pgfplotstableread[row sep=\\,col sep=&]{
            abc & 1 \\
            def & 5 \\
    }\datapoints
    \begin{tikzpicture}
        \begin{axis}[
            % general appearance
            ybar,
            cycle multi list=Dark2-8,
            % x axis
            symbolic x coords={def},
            xtick=data,
            xticklabel style={align=center},
            % y axis
            bar width=0.2cm,
            % legend
            area legend,
            legend entries={1},
            legend pos=north west
        ]
            \addplot table[y=1, x=abc]{\datapoints};
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

enter image description here

My Problem is, that the bar is not filled and I don't really know how to achieve this without adding a manual fill for each addplot.

By the way, if I try to add fill=Dark2-8-1 to the addplot options I get the error ! Package xcolor Error: Undefined color Dark2-8-1.

Can anybody point out where I went wrong?

7

You can add every axis plot/.append style={fill} to solve the fill problem. Also, you can call a specific color from the cycle list by using Dark2-<color letter>, if the cycle list initialized is Dark2-8 a color from the list is Dark2-D.

Code

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{cycle list/Dark2-8}

\begin{document}
    \pgfplotstableread{
        x   y
        a   5
        b   6
        c   4
    }\mytable

    \begin{tikzpicture}
        \begin{axis}[
            ybar,
            symbolic x coords={a,b,c},
            xtick=data,
            every axis plot/.append style={fill},
            cycle list name=Dark2-8
        ]
            \addplot table [y=y, x=x]{\mytable};
            \addplot table [y=y, x=x]{\mytable};
            \addplot[fill=Dark2-D,draw=Dark2-D] coordinates {(a,7) (b,1) (c,2)};
        \end{axis}
    \end{tikzpicture}
\end{document}

Another way, recommended by the PGFPlots manual, to get a particular color from an initialized color scheme, is by using the key index of colormap as follows:

\addplot[index of colormap=3 of Dark2-8] coordinates {(a,7) (b,1) (c,2)};

Result

enter image description here

  • Is there a reference that lists the Dark2-D name scheme? I only found Dark2-8-1. – Rambo Ramon Jul 4 '16 at 22:26
  • 2
    In the section 5.2.4 of PGFPlots manual (v1.13) you can see that a reference to a particular color within every qualitative scheme is made with a letter. Then Dark2-D is not a scheme name by itself, but a particular color within the Dark2-<set> scheme initialized. – OSjerick Jul 4 '16 at 22:37

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.