2

i want the values in each bar. What can I that it works? I want the values in the middle of the bars and change the size. An other idea was to change the zoom for the y values from 0 to 300. How could I do this?

Another problem is that I want other values. At the moment I have this values for the first bar (428.58, 450, 492.09). This is the sum of my data. But I want only the values of the table like (428.58, 21.43, 42.08).

Thanks for your time and invaluable help guys!

\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.9, }

\pgfplotstableread{ % data 
    Label n a b
    450.01 428.58 21.43 42.08
    500 471.31 28.69 46.75
    550 514.06 35.94 51.43
    600 556.80 43.20 56.10
    650 599.55 50.45 60.78
    700 642.29 57.71 65.45
    750 685.04 64.96 70.13
    800 727.78 72.22 74.80
    850 770.52 79.48 79.48
}\testdata


\begin{tikzpicture}[scale=0.70]
        \begin{axis}[
            width=\textwidth,
            ybar stacked,   % Stacked horizontal bars
            ymin=0,         % Start x axis at 0
            xtick=data,     % Use as many tick labels as y coordinates
            xticklabels from table={\testdata}{Label},  % Get the labels from the Label column of the \datatable
            grid=major,
            xmajorgrids=false,
            nodes near coords,
        ]
        %[mark=none,smooth, thick]
        \addplot [fill=green!80, bar width=0.6cm] table [y=n, meta=Label,x expr=\coordindex] {\testdata};   
        \addplot [fill=blue!60, bar width=0.6cm] table [y=a, meta=Label,x expr=\coordindex] {\testdata};
        \addplot [fill=red!60, bar width=0.6cm] table [y=b, meta=Label,x expr=\coordindex] {\testdata};
        \end{axis}
\end{tikzpicture}

enter image description here

5
  • To get the values in the middle, and not the sum, add \pgfplotsset{compat=1.14} after \usepackage{pgfplots} (with any compat setting of 1.9 or higher that is the default, see tex.stackexchange.com/q/36114). Oct 2, 2016 at 8:57
  • Thank you very much! Do you also how to change the second problem with the values?
    – ikreb
    Oct 2, 2016 at 10:04
  • Doesn't the compat setting do that as well? Oct 2, 2016 at 10:19
  • @TorbjørnT. it does.
    – Roald
    Oct 2, 2016 at 15:35
  • 4
    I'm voting to close this question as off-topic because it is solved in the comment (by using a newer piece of code.)
    – Symbol 1
    Apr 18, 2017 at 0:58

0

Browse other questions tagged .