6

How can I completely remove the spacing between the bars in a pgfplots stacked bar chart? I've tried using code from this answer, but it doesn't produce a legend. Here's the example from the manual.

\pgfplotsset{width=7cm,compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar stacked]
\addplot coordinates
{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates
{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates
{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\end{axis}
\end{tikzpicture}
\end{document}
0

1 Answer 1

10

You can give the bar width argument in terms of axis lengths. Also for legend, you need to include legend information. One way is providing explicitly the entries. Otherwise please check the manual.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar stacked,legend entries={a,b,c},bar width=1,axis on top]
\addplot coordinates
{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates
{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\addplot coordinates
{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Sorry, may not have been clear. I was using my own graph with a legend, I was just using the doc example for a MWE. This is helpful. I guess I'm approaching PGFPLOTs from a HTML/CSS background, so was looking for something to do with padding.
    – Heuriskos
    Jul 6, 2013 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .