# How to color each column in a bar chart with different colors?

I have the following bar chart and I would like to color each column differently. Both columns are in the same plot, when I separate them just to give a different color values for each one the appearance of the bar chart changes. Is there a way to specify different colors for the same plot?

 \documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{bchart}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{subfig}
\pgfplotsset{compat=1.10}

\definecolor{RYB2}{RGB}{245,245,245}
\definecolor{RYB1}{RGB}{218,232,252}
\definecolor{RYB4}{RGB}{108,142,191}

\begin{document}

\begin{figure}
\centering

\subfloat[][name]{\resizebox{0.45\textwidth}{!}{
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={col1, col2, col3},
xtick=data,
ylabel=Passed Challenges(\%),
xticklabel style={rotate=45,anchor=north east},
ymajorgrids,
bar width=17pt,
]
(col1, 44.71)
(col2, 26.57)
(col3, 45.42)
};
\end{axis}
\end{tikzpicture}}}
\caption{Caption}
\label{fig:my_label}
\end{figure}

\end{document}


Thank you

Just do \addplotfor each column with a defined color.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{bchart}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{subfig}
\pgfplotsset{compat=1.10}

\definecolor{RYB2}{RGB}{245,245,245}
\definecolor{RYB1}{RGB}{218,232,252}
\definecolor{RYB4}{RGB}{108,142,191}

\begin{document}

\begin{figure}
\centering

\subfloat[][name]{\resizebox{0.45\textwidth}{!}{
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={col1,,col2,,col3},
xticklabel style={rotate=45,anchor=north east},
xtick={col1,col2,col3},
ylabel=Passed Challenges(\%),
ymajorgrids,
bar width=17pt,
]
coordinates {(col1,44.71)};

coordinates {(col2,26.57)};

coordinates {(col3,45.42)};

\end{axis}
\end{tikzpicture}}}
\caption{Caption}
\label{fig:my_label}
\end{figure}

\end{document}

• Thank you for your answer, but the name of the second and third columns has eliminated Apr 19 '18 at 14:46
• @User505 Should be fixed now. Added col1,,col2,,col3 in symbolic x coords and xtick.
– AML
Apr 19 '18 at 15:37
• @AML Thanks for that comment, I had the exact same issue. Apr 6 '19 at 19:54