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 want to plot two bar plots next to each other. This works without a problem. However both use the first color defined in a pre or selfdefined colorseries. I tried to modify the color manually in the plot, but the color and fill definitions have no effect:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}

\begin{document}

\pgfplotstableread[header=false, col sep=comma]{ 
1, first item
5, second item
}\datatable

\begin{tikzpicture}
  \begin{axis}[        
    ,xbar
    ,bar width=2ex, y=3ex
    ,enlarge y limits={abs=0.75}
    ,ytick={data} % (\empty,data,{coordinate list})
    ,yticklabels from table={\datatable}{1}
  ]
  \addplot table [
    ,red!20!black,fill=red!80!white,
    y expr=-\coordindex, % Use negative coordinate index as y coordinate
    x index=0 % Use first column as x coordinate
  ] {\datatable};
  \end{axis}
\end{tikzpicture}

\end{document}

The plot is still in the default blue.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

Using the color specification in the optional argument of \addplot (instead of table) seems to work:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}

\begin{document}

\pgfplotstableread[header=false, col sep=comma]{ 
1, first item
5, second item
}\datatable

\begin{tikzpicture}
  \begin{axis}[        
    ,xbar
    ,bar width=2ex, y=3ex
    ,enlarge y limits={abs=0.75}
    ,ytick={data} % (\empty,data,{coordinate list})
    ,yticklabels from table={\datatable}{1}
  ]
  \addplot[red!20!black,fill=red!80!white] table [
    y expr=-\coordindex, % Use negative coordinate index as y coordinate
    x index=0 % Use first column as x coordinate
  ] {\datatable};
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

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.