PGFplots 堆疊長條圖和表格讀取導致間隙和不正確的值

PGFplots 堆疊長條圖和表格讀取導致間隙和不正確的值

我無法正確渲染堆疊長條圖。存在不應該存在的間隙,且值不正確。請看下面的程式碼。有問題的情節

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

相關內容