我无法正确呈现堆叠条形图。存在不应存在的间隙,并且值不正确。请参阅以下代码。
\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}
文件内容如下:
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
答案1
欢迎!删除后\closedcycle
我得到
\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}