1

I have bar chart that consists of 4 bars. I want to add extra four bars so that I can compare the result of each algorithm before and after a certain modification. the bar I have is the following:

enter image description here

and I want something like this (Except that each 2 bars has the same color so each algorithm before and after has the same color):

enter image description here

The code of my first image is:

 \documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[margin=0.5in]{geometry}


%-------------------------------------------------------
%Pseudo Code
\floatname{algorithm}{Pseudo Code}

%-------------------------------------------------------
%Bar chart
\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{RYB3}{RGB}{252,252,252}%
\definecolor{RYB4}{RGB}{108,142,191}%كحلي غامق
\definecolor{RYB5}{RGB}{85, 114, 155}%
\definecolor{RYB6}{RGB}{67, 94, 132}%



%------------------------------------------------------
%Tiks figure
\usetikzlibrary{fit, backgrounds, matrix, arrows.meta}
\tikzset{ 
    startstop/.style={ 
        rectangle, rounded corners, minimum width=1.8cm, 
        minimum height=1.5cm,text centered, draw=black, fill=RYB2 
    }, 
    process/.style={ 
        rectangle, minimum width=3.95cm, minimum height=1cm, text centered, draw=black, fill=RYB1
    }, 
    arrow/.style={ 
        black,-{Stealth[length=6pt]} 
    },     
    arrowlabel/.style={
        midway, above, inner ysep=2pt 
    }, 
    dasharrow/.style={ 
        black, dashed,-{Stealth[length=6pt]} 
    } 
}



\newcommand\stupidfbox[1]
  {%
    \fbox{\scantokens{#1\ignorespaces}}%
  }



\begin{document}



 \begin{figure}[H]
            \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,
                                    ]
                                    \addplot[ybar,fill=RYB2] coordinates {(alg1,44.71)};
                                    \addplot[ybar,fill=RYB1] coordinates {(alg2,26.57)};
                                    \addplot[ybar,fill=RYB4] coordinates {(alg3,37.57)};
                                    \addplot[ybar,fill=RYB5] coordinates {(alg4,39.57)};
                                    
                                    \end{axis}
                                \end{tikzpicture}
            \caption{Figure name}
            \label{fig:results_1}
        \end{figure} 
        
        


\end{document}

Does anyone knows how can I achieve that?

Thank you

1

Welcome to TeX.SE! Most of the efforts in writing this went into removing things that were not needed. And to get the result, I moved ybar to the axis options and then added the plots without it.

\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}

enter image description here

| improve this answer | |
  • Thank you very much for your answer, a small modification is it possible to make each two bar with the same color (each algorithm has its own color)? – CS Student Feb 16 '19 at 8:33
  • 2
    Thank you for your comment. My apology definitely I will mention your answer in that question! I didn't meant to make it as my effort. Please check the date of my edit to make sure if my edit before or after your answer. Thank you once again. – CS Student Feb 17 '19 at 11:38

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.