Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to use absolute coordinates instead of relative values when using a ybar stacked plot. Is this possible? I know I can just reformat my data to be relative, but it sounds like pgfplots could do that job too. I assume my real problem is that what I seek is not 'stacked', but just 'overlay'. Does that exist?

Here is an example from converting an area plot that uses absolute coordinates to a ybar stacked plot to show what I mean.

area plot

\begin{figure}[h]\centering
\begin{tikzpicture}\begin{axis}[area style,xtick=data]
\addplot[red,fill=red] coordinates { (1,8) (2,8) (3,9) (4,10) } \closedcycle;
\addplot[green,fill=green] coordinates { (1,5) (2,7) (3,8) (4,9)  } \closedcycle;
\addplot[blue,fill=blue] coordinates { (1,3) (2,5) (3,7) (4,8)  } \closedcycle;
\end{axis}\end{tikzpicture}
\caption{Original area plot ordered back to front using absolute values that I want to convert to a stacked bar plot instead.}
\end{figure}

stacked relative

\begin{figure}[h]\centering
\begin{tikzpicture}\begin{axis}[ybar stacked,xtick=data]
\addplot[blue,fill=blue] coordinates { (1,3) (2,5) (3,7) (4,8) };
\addplot[green,fill=green] coordinates { (1,2) (2,2) (3,1) (4,1) };
\addplot[red,fill=red] coordinates { (1,3) (2,1) (3,1) (4,1) };
\end{axis}\end{tikzpicture}
\caption{Stacked using base values and relative values, ordered bottom to top. This is the output I desire, but I had to modify the data to be relative.}
\end{figure}

stacked_absolute

\begin{figure}[h]\centering
\begin{tikzpicture}\begin{axis}[ybar stacked,xtick=data]
\addplot[red,fill=red] coordinates { (1,8) (2,8) (3,9) (4,10) };
\addplot[green,fill=green] coordinates { (1,5) (2,7) (3,8) (4,9)  };
\addplot[blue,fill=blue] coordinates { (1,3) (2,5) (3,7) (4,8)  };
\end{axis}\end{tikzpicture}
\caption{Stacked using original absolute data, ordered back to front.}
\end{figure}

As a new user I can't make new keywords, but I wish they were: pgfplots, stacked, ybar, absolute, relative.

share|improve this question
    
Welcome to tex.sx! We don't want to go overboard with tags (keywords) -- e.g., absolute and relative aren't particularly helpful when looking for relevant questions. (And I'm sure that pgfplots is sufficient as a call to the experts. ;-)) –  lockstep Sep 1 '11 at 16:11

1 Answer 1

up vote 2 down vote accepted

You can overlay the bars by setting bar shift=0pt. Note that you should also always set ymin=0 explicitly to make sure the whole columns are visible.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[h]\centering
\begin{tikzpicture}\begin{axis}[
    ybar,
    bar shift=0pt,
    ymin=0,
    xtick=data]
\addplot[red,fill=red] coordinates { (1,8) (2,8) (3,9) (4,10) };
\addplot[green,fill=green] coordinates { (1,5) (2,7) (3,8) (4,9)  };
\addplot[blue,fill=blue] coordinates { (1,3) (2,5) (3,7) (4,8)  };
\end{axis}\end{tikzpicture}
\caption{Stacked using original absolute data, ordered back to front.}
\end{figure}

\end{document}
share|improve this answer
    
Thank you, works like a charm. –  fluxrider Sep 2 '11 at 0:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.