现在我有一些数据
year,0-19 years,20-39 years,40-59 years,60-79 years,80-99 years,100 years+
2015,100,100,100,100,100,100
2016,99.13845985,100.6510799,100.3768131,101.6514052,102.1909752,103.1311155
2017,98.47752007,101.3914524,100.315877,103.2268878,104.8870115,110.665362
2018,97.88886938,102.1734045,100.1076517,104.618223,108.1048883,113.7964775
2019,97.48903691,102.7318398,99.88340414,105.934158,111.6868789,118.1996086
2020,97.24146004,103.3374176,99.56154293,107.1695557,115.2344717,122.407045
我正在绘制我的数据
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
height=0.5\textwidth,
xticklabel style={/pgf/number format/1000 sep=, rotate=45},
]
\pgfplotstableread[col sep=comma]{index.dat}{\loadedtable}
\pgfplotsinvokeforeach{0-19 years,20-39 years,40-59 years,60-79 years,80-99 years,100 years+}{
\addplot table [x=year, y=#1, col sep=comma] {\loadedtable};
\addlegendentry{#1}
}
\end{axis}
\end{tikzpicture}
但在这个例子中,我已经进行了求和以形成 20 年组(0-19、20-39 等)。
如果我有以下数据
year,1 year,2 year,3 year,4 year,[...]
2015,3,4,1,5,[...]
2016,2,1,5,9,[...]
[...]
是否可以pgfplots
进行分组/求和,所以我只需指定 1-19、20-39 等?