1
 \addplot table [x=X, y=4ACH,fill=black,draw=black,bar shift=-0.5ex] {\datatable};

makes no difference to colour of bars.

change color of pgfplot bar plot has the same problem but the workaround doesn't work for me. Any ideas what I'm doing wrong here? Also what's with the legend having two bars?

enter image description here \documentclass[tikz,border=3pt]{standalone} \usepackage{pgfplots, pgfplotstable}

\newcounter{groupcount}
\pgfplotsset{
    draw group line/.style n args={5}{
        after end axis/.append code={
            \setcounter{groupcount}{0}
            \pgfplotstableforeachcolumnelement{#1}\of\datatable\as\cell{%
                \def\temp{#2}
                \ifx\temp\cell
                    \ifnum\thegroupcount=0
                        \stepcounter{groupcount}
                        \pgfplotstablegetelem{\pgfplotstablerow}{X}\of\datatable
                        \coordinate [yshift=#4] (startgroup) at (axis cs:\pgfplotsretval,0);
                    \else
                        \pgfplotstablegetelem{\pgfplotstablerow}{X}\of\datatable
                        \coordinate [yshift=#4] (endgroup) at (axis cs:\pgfplotsretval,0);
                    \fi
                \else
                    \ifnum\thegroupcount=1
                        \setcounter{groupcount}{0}
                        \draw [
                            shorten >=-#5,
                            shorten <=-#5
                        ] (startgroup) -- node [anchor=base, yshift=0.5ex] {#3} (endgroup);
                    \fi
                \fi
            }
            \ifnum\thegroupcount=1
                        \setcounter{groupcount}{0}
                        \draw [
                            shorten >=-#5,
                            shorten <=-#5
                        ] (startgroup) -- node [anchor=base, yshift=0.5ex] {#3} (endgroup);
            \fi
        }
    }
}

\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
X   Gp           Name        4ACH 6ACH
1   Patient1    E   0.0002875   0.00004375
2   Patient1    P   0.0002  0.000133333
3   Patient1    H   0.000382716 0.000290123
4   Patient1    N   0.001195062 0.000562654
5   Patient1    F   0.00201962  0.0016803
6   {}  {}      0 0
7   Patient2    E   0.0002875   0.00004375
8   Patient2    P   0.000533333 0.0002
9   Patient2    H   0.000567901 0.000259259
10  Patient2    N   0.001503395 0.000477778
11  Patient2    F   0.00201962  0.0016803
12  {}  {}      0 0
13  Patient3    E   0.081057143 0.0934
14  Patient3    P   0.0758  0.025466667
15  Patient3    H   0.580506173 0.815259259
16  Patient3    N   0.977954012 0.770544444
17  Patient3    F   0.022212031 0.025019363
18  {}  {}      0 0
19  Patient4    E   0.0002875   0.00004375
20  Patient4    P   0.0758  0.025466667
21  Patient4    H   0.05982716  0.071154321
22  Patient4    N   0.426280247 0.618009568
23  Patient4    F   0.022212031 0.025019363

}\datatable

\begin{axis}[
    %axis lines*=left,
    %ymajorgrids,
    width=12cm, height=6cm,
    ymin=0,
    ybar,
    bar width=3pt,
    xtick=data,
    ymax=2.5,
    xticklabels from table={\datatable}{Name},
    xticklabel style={rotate=0,yshift=-1.5ex,xshift=0ex,anchor=mid },
    draw group line={Gp}{Patient1}{Patient1}{-6ex}{5pt},
    draw group line={Gp}{Patient2}{Patient2}{-6ex}{5pt},
    draw group line={Gp}{Patient3}{Patient3}{-6ex}{5pt},
    draw group line={Gp}{Patient4}{Patient4}{-6ex}{5pt},
    ylabel={CFU cm$^2$},
    after end axis/.append code={
        \path [anchor=base east, yshift=0.5ex]
            %(rel axis cs:0,0) node [yshift=-10ex]{Conc 1}
            %(rel axis cs:0,0) node [yshift=-7ex] {Conc 2}
            %(rel axis cs:0,0) node [yshift=-6ex] {Patient \#}
            ;
    }
]

\addplot table [x=X, y=4ACH,fill=black,draw=black,bar shift=-0.5ex] {\datatable}; \addlegendentry{4  ac.h$^{-1}$}
\addplot table [x=X, y=6ACH,fill=white,draw=black,bar shift=0.5ex] {\datatable}; \addlegendentry{6  ac.h$^{-1}$}

\end{axis}
\end{tikzpicture}


\end{document}
  • The options need to be supplied to the \addplot [...] options, not the table [...], so you have to say \addplot [fill=black, draw=black, bar shift=-0.5ex] table [x=X, y=4ACH] {\datatable}; – Jake Apr 19 '13 at 10:23
  • D'oh! :=) Thank you for the quick response! By the way is there a GUI program which creates graphs for latex documents? I wish I could get the cm fonts for the pc then two mins in excel and job done. Messing about with the data and whatnot for that graph has taken 2 hours. – HCAI Apr 19 '13 at 10:53
  • I don't know of a GUI specifically for that, although I guess matlab2tikz comes close. Personally, I think it's much easier to get consistent graphs quickly when using something like PGFPlots without a GUI: Once you've set up your plot styles, all you need to do is change the data file, and you're done. – Jake Apr 19 '13 at 11:36

Browse other questions tagged or ask your own question.