# Set a colormap to fill a bar plot using pgfplots

I'm trying to change the default color of the bar plot with a a colormap without success.

The thing is that I don't like the default color sequence. However, I was wondering if there is a way of automatically switching between colors. I try using the cycle list name but it only changes the line and doesn't fill the bars. Is there any hope or do I have to set the colors by hand every time in the \addplot command?

This is an example of what I have

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{width=\linewidth,compat=1.3}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}
\begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Population,
enlargelimits=0.05,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ybar interval=0.7,
cycle list name=color listenter code here
]
coordinates {(1930,50e6) (1940,33e6)
(1950,40e6) (1960,50e6) (1970,70e6)};
coordinates {(1930,38e6) (1940,42e6)
(1950,43e6) (1960,45e6) (1970,65e6)};
coordinates {(1930,15e6) (1940,12e6)
(1950,13e6) (1960,25e6) (1970,35e6)};
coordinates {(1930,15e6) (1940,12e6)
(1950,13e6) (1960,25e6) (1970,35e6)};

\legend{Far,Near,Here,There}
\end{axis}
\end{tikzpicture}

\end{document}

-

Pgfplots' manual page 58 explains how to declare a bar cycle list with your preferred colors, so include something like

\pgfplotsset{
/pgfplots/bar  cycle  list/.style={/pgfplots/cycle  list={%
{orange,fill=orange!30!white,mark=none},%
{yellow,fill=yellow!30!white,mark=none},%
{brown!60!black,fill=brown!30!white,mark=none},%
{green,fill=green!30!white,mark=none},%
}
},
}


in your document and will obtain

-
you beat me to it :) And your answer shows that there are multiple ways to achieve the goal with TikZ :) – Habi Nov 11 '11 at 9:57
@Habi, Ignasi: Thanks for the quick reply, so at the end I have to define the colors by hand. Is it possible to use a colormap or something? What I was trying is to avoid the manual definition, because if I have, let say 10 bars, I have to define 10 different colors, and the same if it is changing. – adn Nov 11 '11 at 10:58
@adn: It seems that all cycle lists in pgfplots.code.tex file doesn't include a fill declaration, so when you say cycle list name=exotic bars are empty. You have some options, first, use Habi's or mine solutions, second fill a bug (or wish) report in pgfplots or send a message to pgfplots-users list and third hope that Christian Feuersänger read your question and provide a better solution ;-) – Ignasi Nov 11 '11 at 11:29
Thanks for your help, I got the idea, why isn't working. – adn Nov 11 '11 at 12:12

According to the pgfplots-Manual (page 133) you have to define yourself a color list to use it later.

I've adapted your example (also with a - I think - nice trick with \usepackage{preview}), is that what you've intended??

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage[pdftex,active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\pgfplotscreateplotcyclelist{mylist}{%
{blue,mark=*,fill=green},
{color=red,mark=square},
{dashed,mark=o},
{dotted,mark=+,fill=orange}}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
x tick label style={/pgf/number format/1000 sep=},
ylabel=Population,
enlargelimits=0.05,
legend style={at={(0.5,-0.15)},anchor=north,legend columns=-1},
ybar interval=0.7,
cycle list name=mylist
]
coordinates {(1930,50e6) (1940,33e6) (1950,40e6) (1960,50e6) (1970,70e6)};
coordinates {(1930,38e6) (1940,42e6) (1950,43e6) (1960,45e6) (1970,65e6)};

Nice answer also. Probably more general than mine. Although its final goal is not the same, I use standalone class instead of preview. You just need to type \documentclass[border=3mm]{standalone} to obtain same result. – Ignasi Nov 11 '11 at 10:20