2

I want to create a vertical bar charts with two bars in it. At the x-axis the bars shall be labeled with A and B. The label A is printed although it is not exactly properly positioned, but the label B seems to be swallowed entirely by something. See my attachment. Can someone tell me what I am missing?

enter image description here

Here is a MWE of my plot

\documentclass{article}
\usepackage{pgfplots}   

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    enlargelimits=0.4,
    symbolic x coords={A,B},
    xtick=data,
    nodes near coords,
    ]
\addplot coordinates {(A,7)};
\addplot coordinates {(B,4)};
\end{axis}
\end{tikzpicture}
\end{document}
  • I think you need \addplot coordinates {(A,7)(B,4)}; – percusse Nov 9 '15 at 11:06
  • I want the two bars to have different colours. – toobee Nov 9 '15 at 12:16
3

You can use [bar shift=0pt] to overwrite the original bar with one of a different color.

\documentclass{article}
\usepackage{pgfplots}   

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    enlargelimits=0.4,
    symbolic x coords={A,B},
    xtick=data,
    nodes near coords,
    bar shift=0pt
    ]
\addplot coordinates {(A,7)(B,4)};
\addplot coordinates {(B,4)};
\end{axis}
\end{tikzpicture}
\end{document}

bar plot

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.