2

I have a multi-bar plot that contains single and multi bars:

enter image description here

I want to make the single bars A and D in the center; right now they are left aligned.

The following is the code:

\begin{tikzpicture}
        \begin{axis}[
        ybar, axis on top, height=8cm, width=8cm, bar width=0.6cm,  ymajorgrids, tick align=inside,
        major grid style={draw=white}, enlarge y limits={value=0.1,upper}, ymin=0, ymax=40,
        axis x line*=bottom, axis y line*=left, y axis line style={opacity=0}, tickwidth=0pt, 
        enlarge x limits=true, 
        ylabel={Percentage (\%)}, 
        ylabel style={align=center},
        symbolic x coords={
            A,B,C,D
        },
        xtick=data,
        nodes near coords={
            \pgfmathprintnumber[precision=1]{\pgfplotspointmeta}
        },
        x tick label style={font=\small,text width=2cm,align=center}
        ]
        \addplot [draw=none, fill=blue!60] coordinates {
            (A, 25.6)
            (B, 10.3) 
            (C, 35.7)
            (D, 22.4)  };
        \addplot [draw=none,fill=red!30,opacity=1] coordinates {
            (B, 19.6) 
            (C, 26.1) };
        \end{axis}
        \end{tikzpicture}
  • Welcome to TeX.SX. Those are actually center aligned. Since you don't have data in the second set (red) for A and D, those bars are not plotted but the space for that is allotted. That's why it looks left aligned. – nidhin Dec 10 '18 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.