1

I am trying to create a horizontal bar chart like the one in the picture below. For that I want to use data stored in a table like this:

\pgfplotstableread[col sep=comma]{
system,   Tmin, Tmax, limitmin, limitmax
{a},      20,     50,     10,      30
{b},     10,     60,     15,      60
{c},      15,     78,     0,       0

}\datatable

What I want

The closest I came to a result was by manually typing in the coordinates. But the stacked bar chart keeps adding/ subtracting the values and I cant figure out how to let a bar start from a value different to zero.

\begin{tikzpicture}
\begin{axis}[
xbar stacked,
stack negative=on previous ,
xlabel={Temperature $^{\circ}C$},
symbolic y coords={%
    {A},
    {B},
    {C}},
ytick=data,
%nodes near coords, 
%nodes near coords align={horizontal},
ytick=data,
xmajorgrids,
legend
]

\addplot+[blue, fill=blue, bar shift =-5pt] coordinates { (14,{A}) (5,{B}) (14,{C}) }; \addplot+[blue, fill=blue, bar shift =-5pt] coordinates { (-20,{A}) (-10,{B}) (14,{C}) }; \addplot+[red, fill=red, bar shift =5pt] coordinates { (20,{A}) (5,{B}) (14,{C}) };

\addplot+[red, fill=red, bar shift =5pt] coordinates { (-20,{A}) (-10,{B}) (14,{C}) };

\end{axis} \end{tikzpicture}

enter image description here

There is probably a proper way to do this but I am still new to tikz and pgfplots and could not find a good example. Thanks for your help!

Enclds
  • 11
  • 1
    Welcome to TeX.SE! – Mensch Jun 14 '21 at 12:50
  • Thanks for your efforts but I still cant have the minimum of a bar start at a value not equal to 0. Any ideas? – Enclds Jun 15 '21 at 00:08
  • Since this question is closed, I can't post an answer. And the code is too long for a single comment.

    `\documentclass{standalone} \usepackage{pgfplots}

    \begin{document} \pgfplotstableread[col sep=comma]{ system, Tmin, Tmax, limitmin, limitmax {a}, 20, 50, 10, 30 {b}, 10, 60, 15, 60 {c}, 15, 78, 0, 0 }{\datatable}

    \begin{tikzpicture} \begin{axis}[xlabel=Temperature, xbar, ytick distance=1, enlarge x limits=0.15, bar width=0.8em, symbolic y coords={a, b, c, d, e}, grid=both, ]`…

    – NBur Jun 15 '21 at 06:36
  • …`\addplot +[forget plot] table [x index=1, y index=0] {\datatable}; \addplot table [x index=2, y index=0] {\datatable}; \addlegendentry{T}

    \addplot +[forget plot] table [x index=3, y index=0] {\datatable}; \addplot table [x index=4, y index=0] {\datatable}; \addlegendentry{Limit} \end{axis} \end{tikzpicture} \end{document}`

    – NBur Jun 15 '21 at 06:36
  • Thanks, but the bars still start at zero instead of Tmin/ limitmin. – Enclds Jun 15 '21 at 12:20

0 Answers0