1

I made a plot but it's not at all what I want. There are two things I'm having trouble with: 1.) The bars should be at the bottom, but there's a space between them and the x-axis. 2.) E1/E4, E2/E5 and E3/E6 should have the same color.

Here's a picture of how it is and how I want it below: enter image description here

And here's my code:

\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={E1, E4 (dyn.), E2, E5 (dyn.), E3, E6 (dyn.)},
xtick=data,
width=\linewidth,
height=6cm
]
\addplot[ybar,fill=blue, bar width = 1cm] coordinates {
    (E1,   8)
    (E2,  15)
    (E3,   50)
    (E4 (dyn.), 4)
    (E5 (dyn.), 17)
    (E6 (dyn.), 40)

};
\end{axis}
\end{tikzpicture}
\end{document}

I hope you can help me. Thanks.

Zelos
  • 11

1 Answers1

1

For fixing the y-axis, add ymin=0 to the axis environment. And to get different colors, you can seperate your plot into 3, each with a different color.

Edit: I must have been blind. The original solution did not show the labels for the last 4 x coords. To fix this, xtick=data must be replaced with xtickmin=E1, xtickmax=E6 (dyn.).

\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=0,% added
symbolic x coords={E1, E4 (dyn.), E2, E5 (dyn.), E3, E6 (dyn.)},
%xtick=data, % replaced
xtickmin=E1, xtickmax=E6 (dyn.),
width=\linewidth,
height=6cm
]
% seperated into 3 plots
\addplot[ybar,fill=blue!50, bar width = 1cm] coordinates {
    (E1,   8)
    (E4 (dyn.), 4)
};
\addplot[ybar,fill=red!50, bar width = 1cm] coordinates {
    (E2,  15)
    (E5 (dyn.), 17)
};
\addplot[ybar,fill=green!50, bar width = 1cm] coordinates {
    (E3,   50)
    (E6 (dyn.), 40)
};
\end{axis}
\end{tikzpicture}
\end{document}
Mike
  • 8,664