Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 list`enter code here`
]
\addplot
coordinates {(1930,50e6) (1940,33e6)
(1950,40e6) (1960,50e6) (1970,70e6)};
\addplot
coordinates {(1930,38e6) (1940,42e6)
(1950,43e6) (1960,45e6) (1970,65e6)};
\addplot
coordinates {(1930,15e6) (1940,12e6)
(1950,13e6) (1960,25e6) (1970,35e6)};
\addplot
coordinates {(1930,15e6) (1940,12e6)
(1950,13e6) (1960,25e6) (1970,35e6)};

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


\end{document}
share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

enter image description here

share|improve this answer
    
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
    ]
\addplot
    coordinates {(1930,50e6) (1940,33e6) (1950,40e6) (1960,50e6) (1970,70e6)};
\addplot
    coordinates {(1930,38e6) (1940,42e6) (1950,43e6) (1960,45e6) (1970,65e6)};
\addplot
    coordinates {(1930,15e6) (1940,12e6) (1950,13e6) (1960,25e6) (1970,35e6)};
\addplot
    coordinates {(1930,15e6) (1940,12e6) (1950,13e6) (1960,25e6) (1970,35e6)};

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

preview

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.