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
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}
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!


`\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=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