2

Based on my origin question here: Broken bar diagram with tikz package

I am trying to color each single of a group differently. In my preamble I have defined the colors I want to use:

\definecolor{blue}{RGB}{0,150,214}
\definecolor{greenaccent}{RGB}{0,139,43}
\definecolor{purpleaccent}{RGB}{130,41,128}
\definecolor{orangeaccent}{RGB}{240,83,50}

and pgfplots is loaded right after xcolor. At the moment my code looks like this:

\begin{figure}
\centering
    \begin{tikzpicture}
      \begin{axis}[
        width=\linewidth,
        ybar,
        bar width=7.5pt,
        ymin=0,
        enlarge x limits={abs=25pt},
        legend style={draw=none,at={(0.5,-0.15)},
        anchor=north,legend columns=-1},
        xlabel={Jahre},
        ylabel={Fotos pro Tag (in Millionen)},
        symbolic x coords={2008,2009,2010,2011,2012,2013,2014},
        xtick=data,
      ]
        \pgfplotsinvokeforeach{Facebook,Instagram,Snapchat,WhatsApp}{
        \addplot[
            draw opacity=0,
            fill=blue
        ] table[col sep=semicolon,x=Jahr,y=#1]{./Bilder/AnzahlSocialNetwork.csv};
        \addlegendentry{#1}
        }
    \end{axis}
    \end{tikzpicture}
    \caption{Anzahl der täglich hochgeladenen Fotos (in Millionen)}
    \label{fig:AnzahlTäglichFotosSocialNetwork}
\end{figure}

but the fill option inside \addplot colors everything blue (obviously). What I need is something where I can define the first y graph to be blue, the second one green, third purple, and last orange as per defined colors. In the manual it was written that one can use the bar cycle list but I could not find a option where I can use RGB values like defined here (instead of percentage of a color).

1 Answer 1

2

You can pass it to a cycle list key however you need to put a + sign after the \addplot command to make it understand as /.append style as opposed to overwriting /.style to use the cycle list argument. You can turn off the drawing with draw=none.

And please don't overwrite existing color names for your own sake :)

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotstableread[col sep=comma]{
Year, Facebook, Instagram, Snapchat, WhatsApp
2008, 17, 0,0,0
2009,69,0,0,0
2010,197,0,0,0
2011,249,9,0,0
2012,300,9,51,0
2013,343,51,394,394
2014,351,60,703,703
}\mytable

\definecolor{blueaccent}{RGB}{0,150,214}
\definecolor{greenaccent}{RGB}{0,139,43}
\definecolor{purpleaccent}{RGB}{130,41,128}
\definecolor{orangeaccent}{RGB}{240,83,50}

\begin{tikzpicture}
  \begin{axis}[
    width=\linewidth,
    ybar,
    bar width=7.5pt,
    ymin=0,
    enlarge x limits={abs=25pt},
    legend style={draw=none,at={(0.5,-0.15)},
    anchor=north,legend columns=-1},
    xlabel={Jahre},
    ylabel={Fotos pro Tag (in Millionen)},
    symbolic x coords={2008,2009,2010,2011,2012,2013,2014},
    xtick=data,
    cycle list={blueaccent,greenaccent,purpleaccent,orangeaccent}
  ]
    \pgfplotsinvokeforeach{Facebook,Instagram,Snapchat,WhatsApp}{
      \addplot+[draw=none,fill,] table[x=Year,y=#1]{\mytable};
      \addlegendentry{#1}
    }
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1
  • draw=none is the border/edge around each bar in a darker color of the same color right? I read in another answer that draw opacity = 0 would do that but either way it works so I am happy. Thanks
    – sceiler
    Commented Jun 3, 2015 at 17:20

You must log in to answer this question.

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