16

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.

19

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

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.