3

I am having problem with the following code which is supposed to produce a simple stacked graph.

\documentclass[tikz,border=2pt]{standalone}

\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar stacked]
\addplot[fill=black]    coordinates {(0.00,0.10)};
\addplot[fill=black!66] coordinates {(0.00,0.20)};
\addplot[fill=black!33] coordinates {(0.00,0.30)};
\addplot[fill=white]    coordinates {(0.00,0.40)};
\end{axis}
\end{tikzpicture} 

\end{document}

Below is the output it generates which is not clearly well-aligned. If I explicitly specify ymin = -0.1, ymax = 1.1, the bar looks almost right, but it starts slightly below (0,0). If I replace coordinates (0.00,0.10) with (0.00,0.00), the bar looks just fine. I have absolutely no idea what the problem could be.

enter image description here

1

Adding enlarge y limits=0.15 to the axis option is one possible solution.

enter image description here

Code

\documentclass[tikz,border=2pt]{standalone}

\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.8} 
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar stacked,enlarge y limits=0.15]
\addplot[fill=black]    coordinates {(0.00,0.10)};
\addplot[fill=black!66] coordinates {(0.00,0.20)};
\addplot[fill=black!33] coordinates {(0.00,0.30)};
\addplot[fill=white]    coordinates {(0.00,0.40)};
\end{axis}
\end{tikzpicture} 

\end{document}

4
  • 1
    This looks different on my computer (the lowest segment starts below 0). What version of PGFPlots are you using? I'm using 1.10.
    – Jake
    May 20 '14 at 6:58
  • Gee, I forgot there is a minimal length to write in a comment. Keep giving me errors -- Mine is 1.8.
    – Jesse
    May 20 '14 at 7:07
  • Mine is also 1.10, though it still doesn't work for me even with \pgfplotsset{compat=1.8}
    – Ali
    May 22 '14 at 18:06
  • @Ali -- thank you for your feedback. I tried and tried and tried again with xelatex and pdflatex, same output as I had shown. This is indeed generated by MiKTeK_Portable\tex\generic\pgfplots\pgfplots.revision.tex) Package: pgfplots 2013/03/17 v1.8 Data Visualization (1.8-3-gaf58a29).
    – Jesse
    May 22 '14 at 19:34

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.