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.

enter image description here

I have drawn the above figure using powerpoint, how can I plot something similar using tikz?

I want the 3 different sections in every bar which should ve 3 different colors

---------edit after 1st answer------

I am using the code from 1st answer but all my bars are overlapping why?

    \documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}


\begin{document}

\begin{tikzpicture}
\pgfplotstableread{ % Read the data into a table macro
Label   First   Second  Third
10      0.1     0.3     0.3
20      0.2     0.3     0.3
30      0.3     0.4     0.5
40      0.3     0.5     0.8
160     0.5     0.9     1.5
}\datatable

\begin{axis}[
    xbar stacked,   % Stacked horizontal bars
    xmin=0,         % Start x axis at 0
    ytick=data,     % Use as many tick labels as y coordinates
    yticklabels from table={\datatable}{Label}  % Get the labels from the Label column of the \datatable
]
\addplot [fill=yellow] table [x=First, y expr=\coordindex] {\datatable};    % Plot the "First" column against the data index
\addplot [fill=green!70!blue]table [x=Second, y expr=\coordindex] {\datatable};
\addplot [fill=red!80!yellow] table [x=Third, y expr=\coordindex] {\datatable};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here -------edit------

I updated my pgfplots package and now everything is working as expected!

share|improve this question
1  
You should be able to work out something using this question: tex.stackexchange.com/questions/22429/…. Basically, look at pgfplots to make this type of graphs. –  Mythio Feb 25 '13 at 10:59
add comment

1 Answer

up vote 8 down vote accepted

You can use PGFPlots for this. It has an xbar stacked style that uses stacked horizontal bars. Here's an example based on your image:

\documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}


\begin{document}

\begin{tikzpicture}
\pgfplotstableread{ % Read the data into a table macro
Label   First   Second  Third
10      0.1     0.3     0.3
20      0.2     0.3     0.3
30      0.3     0.4     0.5
40      0.3     0.5     0.8
160     0.5     0.9     1.5
}\datatable

\begin{axis}[
    xbar stacked,   % Stacked horizontal bars
    xmin=0,         % Start x axis at 0
    ytick=data,     % Use as many tick labels as y coordinates
    yticklabels from table={\datatable}{Label}  % Get the labels from the Label column of the \datatable
]
\addplot [fill=yellow] table [x=First, y expr=\coordindex] {\datatable};    % Plot the "First" column against the data index
\addplot [fill=green!70!blue]table [x=Second, y expr=\coordindex] {\datatable};
\addplot [fill=red!80!yellow] table [x=Third, y expr=\coordindex] {\datatable};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
why are all bars overlapping when I use the same code? –  user494461 Feb 25 '13 at 11:29
    
Are you using exactly the same code? Then they shouldn't be overlapping. Are you sure that you have the y expr=\coordindex keys in your code? –  Jake Feb 25 '13 at 11:46
    
yes...i ve just changed the value inside the table...but nothing else –  user494461 Feb 25 '13 at 11:47
    
@user494461: Please edit your question to include the complete code (including the changed values) –  Jake Feb 25 '13 at 11:48
    
i have edited my orignal question –  user494461 Feb 25 '13 at 11:52
show 4 more comments

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.