1

I have a bar chart where the first bar of each of two bars have the same color and the same for the second bar. The bar chart I have is the following:

enter image description here

The code to produce it is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{float}
\pgfplotsset{compat=1.10}

\definecolor{RYB2}{RGB}{245,245,245}%AAAAAAAAAAAAAAA
\definecolor{RYB1}{RGB}{218,232,252}%
\definecolor{RYB3}{RGB}{252,252,252}%
\definecolor{RYB4}{RGB}{108,142,191}%AAAAAAAAAAAA AAAAAAAAAAAA
\definecolor{RYB5}{RGB}{85, 114, 155}%
\definecolor{RYB6}{RGB}{67, 94, 132}%

\begin{document}
\begin{figure}[htb]
 \centering    
 \begin{tikzpicture}
   \begin{axis}[symbolic x coords={alg1,, alg2,,alg3,, alg4},
     xticklabel style={rotate=45,anchor=north east},
     xtick={alg1,, alg2,,alg3,, alg4},
     ylabel=Measure(\%),
     ymajorgrids,
     bar width=17pt,ybar,enlargelimits=0.1
     ]
     \addplot[fill=RYB1] coordinates {(alg1,44.71) 
     (alg2,26.57) (alg3,37.57) (alg4,39.57)};
     \addplot[fill=RYB4] coordinates {(alg1,24.71) 
     (alg2,16.57) (alg3,27.57) (alg4,59.57)};
   \end{axis}
 \end{tikzpicture}
 \caption{Figure name}
 \label{fig:results_1}
\end{figure} 
\end{document}

Is there a way to make each two bar charts have the same color?

The original code I have post is taken from @marmot 's answer in this question. Special thanks for his/her effort it is really appreciated.

Thank you

2

I don't think I understand your question well. If you want two bars to have the same color, just use the same color option in \addplot. Here I use RYB4

\documentclass[tikz,margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\definecolor{RYB2}{RGB}{245,245,245}%AAAAAAAAAAAAAAA
\definecolor{RYB1}{RGB}{218,232,252}%
\definecolor{RYB3}{RGB}{252,252,252}%
\definecolor{RYB4}{RGB}{108,142,191}%AAAAAAAAAAAA AAAAAAAAAAAA
\definecolor{RYB5}{RGB}{85, 114, 155}%
\definecolor{RYB6}{RGB}{67, 94, 132}%

\begin{document}
 \begin{tikzpicture}
   \begin{axis}[symbolic x coords={alg1,, alg2,,alg3,, alg4},
     xticklabel style={rotate=45,anchor=north east},
     xtick={alg1,, alg2,,alg3,, alg4},
     ylabel=Measure(\%),
     ymajorgrids,
     bar width=17pt,ybar,enlargelimits=0.1
     ]
     \addplot[fill=RYB4] coordinates {(alg1,44.71) 
     (alg2,26.57) (alg3,37.57) (alg4,39.57)};
     \addplot[fill=RYB4] coordinates {(alg1,24.71) 
     (alg2,16.57) (alg3,27.57) (alg4,59.57)};
   \end{axis}
 \end{tikzpicture}
\end{document}

enter image description here

Edit:

In case you want each alg has the same color, this is a non-pgfplots solution

\documentclass[tikz,margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
% Axis
\draw (0,1.3) rectangle (5.5,6.5);
\foreach \i in {2,...,6} {
    \draw[thin,gray!50] (0,\i)--(5.5,\i);
    \draw (0,\i) node[left] {\i0} -- (.1,\i);
}
\foreach \i [count=\ct] in {0.5,2,3.5,5} {
    \draw (\i,1.3)--(\i,1.2) node[below] {alg\ct};
    \draw (\i,6.5)--(\i,6.6);
}
\node[rotate=90,above=4ex] at (0,3.9) {Measure (\%)};
% Bars
\path[fill=red,draw=black,very thin] (0,1.3) rectangle (0.475,4.471) (0.525,1.3) rectangle (1,2.471);
\path[fill=yellow,draw=black,very thin] (1.5,1.3) rectangle (1.975,2.657) (2.025,1.3) rectangle (2.5,1.657);
\path[fill=green,draw=black,very thin] (3,1.3) rectangle (3.475,3.757) (3.525,1.3) rectangle (4,2.757);
\path[fill=blue,draw=black,very thin] (4.5,1.3) rectangle (4.975,3.957) (5.025,1.3) rectangle (5.5,5.957);
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    If I understood the question correctly, he wants each new pair to be the same color. But not all of the same color. – AndréC Feb 17 at 8:10
  • 2
    @AndréC Yes, thank you for clarifying my question, and thanks to JouleV for his effort. – CS Student Feb 17 at 11:47
  • 1
    @CSStudent You're welcome. – AndréC Feb 17 at 11:56

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.