![使用 pfgplots 计算曲线总和](https://linux22.com/image/457706/%E4%BD%BF%E7%94%A8%20pfgplots%20%E8%AE%A1%E7%AE%97%E6%9B%B2%E7%BA%BF%E6%80%BB%E5%92%8C%20.png)
我有四条曲线,我已将其导入并使用 pfgplots 绘制。我想将这些曲线绘制在一起,而不是绘制四条单独的曲线。我可以使用电子表格并准备数据来执行此操作,但 pfgplots 中是否有选项可以执行此操作?
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{filecontents*}{data.csv}
Category,Oil tankers,Bulk carriers,General cargo,Container ships,Other types of ships
1981,338.616336,184.501243,114.832851,11.060523,30.693841
1982,334.237813,193.217208,113.293837,12.108264,33.171788
1983,323.668186,204.630713,113.269092,12.809767,35.715383
1984,304.466296,212.91521,111.863049,14.08879,38.205507
1985,284.94586,218.518136,108.308363,17.26677,39.10101
1986,258.932401,227.55078,103.920992,18.732552,45.190681
1987,238.144528,226.967377,100.221979,20.180653,46.723246
1988,234.908375,223.65913,97.110251,21.489531,47.87848
1989,233.608542,222.432047,93.795681,22.295221,48.602749
1990,235.785,223.619,100.457,22.346,47.77
1991,244.818,230.028,102.109,23.611,50.716
1992,255.657238,236.14308,102.931705,27.25189,52.437161
1993,261.081516,234.696615,104.193343,29.844257,53.823315
1994,269.289312,236.843255,106.185603,32.045907,55.380428
1995,270.942439,250.142436,103.50283,38.92335,55.705119
1996,266.708185,261.168634,103.052431,43.805665,57.135544
1997,270.899061,271.70229,103.556122,48.732522,60.407948
1998,271.633253,280.05518,102.56326,56.076257,62.473229
1999,280.27691,274.689582,101.75705,61.154933,67.452597
2000,283.065653,274.445412,101.519612,63.580494,71.159623
2001,284.864321,280.323408,99.895172,69.124018,68.564568
2002,286.00144,294.779972,95.693187,77.328677,68.208183
2003,308.6831,296.140235,96.457007,83.28135,57.173283
2004,320.657846,308.935209,94.330978,91.621149,48.122278
2005,340.748411,325.665804,91.827046,100.226403,49.006644
2006,356.109224,349.720569,96.39192,112.70216,52.248601
2007,382.975034,367.542469,100.93423,128.321475,62.554414
2008,407.880862,391.126986,105.491688,144.654719,68.624309
2009,418.266449,418.356026,108.880834,161.918957,84.894956
2010,450.052685,456.623242,108.231551,169.157522,92.072155
2011,440.1108117,547.191632,82.41399546,183.691408,164.9744412
2012,454.5287487,624.021922,79.71803998,196.820992,182.394155
2013,473.928389,689.74316,79.44432621,206.322135,184.591796
2014,481.8464129,730.295568,76.42964257,216.199135,189.7483375
2015,491.0583439,762.322448,76.01185491,228.229988,195.4693094
2016,505.9549486,779.289319,76.48112436,244.338846,205.1503341
2017,535.0312895,795.585722,75.52187137,245.683478,216.3513931
2018,563.1882837,822.905785,75.70172438,253.632593,222.3486367
2019,568.0373699,846.461296,76.42495894,266.129351,232.8711747
2020,601.3418545,879.725286,76.89335333,274.972535,238.7050534
2021,619.1476445,913.032281,76.75398161,281.783764,243.922236
\end{filecontents*}
\begin{document}
\pgfsetplotmarksize{0pt}
\begin{tikzpicture}
\begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Millions of dead-weight ton,
legend style={
at={(0.05,0.95)},
anchor=north west}]
\addplot[line width=1pt] table [x=Category, y=Oil tankers, col sep=comma] {data.csv};
\addlegendentry{Oil tankers}
\addplot[line width=1pt, red] table [x=Category, y=Bulk carriers, col sep=comma] {data.csv};
\addplot[line width=1pt, blue] table [x=Category, y=General cargo, col sep=comma] {data.csv};
\addplot[line width=1pt, green] table [x=Category, y=Container ships, col sep=comma] {data.csv};
\legend{Oil tankers,Bulk carriers,General cargo,Container ships}
\end{axis}
\end{tikzpicture}
\end{document}