Ich habe Probleme, einen gestapelten Balken richtig darzustellen. Es gibt eine Lücke, die nicht da sein sollte, und die Werte sind nicht korrekt. Bitte sehen Sie sich den Code unten an.
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.16}
\usepackage{tikz}
\usetikzlibrary{positioning}
\definecolor{butter1}{rgb}{0.988,0.914,0.310}
\definecolor{chocolate1}{rgb}{0.914,0.725,0.431}
\definecolor{chameleon1}{rgb}{0.541,0.886,0.204}
\definecolor{plum1}{rgb}{0.678,0.498,0.659}
\pgfplotsset{width=7in,height=5in}
\pgfplotstableread{TDsummary_2.tsv}\loadedtable
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
bar width=60pt,
enlarge x limits=0.09,
symbolic x coords={B, SC1, SC2, SC3},
xtick=data,
cycle list={%
{fill=butter1},%
{fill=chocolate1},%
{fill=chameleon1},%
{fill=plum1},},
ylabel={Energy, MWh},
]
\addplot table[x=scen,y=F] from \loadedtable \closedcycle;
\addplot table[x=scen,y=S] from \loadedtable \closedcycle;
\addplot table[x=scen,y=C] from \loadedtable \closedcycle;
\addplot table[x=scen,y=O] from \loadedtable \closedcycle;
\legend{F, S, C, O}
\end{axis}
\end{tikzpicture}
\end{document}
Der Dateiinhalt ist:
scen C O S F
B 0 18679 118488 116009
SC1 0 18679 118488 116009
SC2 22483 18679 118488 116009
SC3 719944 18679 118488 116009
Antwort1
Willkommen! Nach dem Entfernen \closedcycle
bekomme ich
\documentclass[border=5pt]{standalone}
\begin{filecontents*}{TDsummary_2.tsv}
scen C O S F
B 0 18679 118488 116009
SC1 0 18679 118488 116009
SC2 22483 18679 118488 116009
SC3 719944 18679 118488 116009
\end{filecontents*}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.16}
\usepackage{tikz}
\usetikzlibrary{positioning}
\definecolor{butter1}{rgb}{0.988,0.914,0.310}
\definecolor{chocolate1}{rgb}{0.914,0.725,0.431}
\definecolor{chameleon1}{rgb}{0.541,0.886,0.204}
\definecolor{plum1}{rgb}{0.678,0.498,0.659}
\pgfplotsset{width=7in,height=5in}
\pgfplotstableread{TDsummary_2.tsv}\loadedtable
\begin{document}
\begin{tikzpicture}
\begin{axis}[ ybar stacked,
bar width=60pt,
enlarge x limits=0.09,
symbolic x coords={B, SC1, SC2, SC3},
xtick=data,
cycle list={%
{fill=butter1},%
{fill=chocolate1},%
{fill=chameleon1},%
{fill=plum1},},
ylabel={Energy, MWh},
]
\addplot table[x=scen,y=F] from \loadedtable ;
\addplot table[x=scen,y=S] from \loadedtable ;
\addplot table[x=scen,y=C] from \loadedtable;
\addplot table[x=scen,y=O] from \loadedtable;
\legend{F, S, C, O}
\end{axis}
\end{tikzpicture}
\end{document}