![如何绘制此类图表:带有垂直误差指示器的线图](https://linux22.com/image/475521/%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%E6%AD%A4%E7%B1%BB%E5%9B%BE%E8%A1%A8%EF%BC%9A%E5%B8%A6%E6%9C%89%E5%9E%82%E7%9B%B4%E8%AF%AF%E5%B7%AE%E6%8C%87%E7%A4%BA%E5%99%A8%E7%9A%84%E7%BA%BF%E5%9B%BE.png)
我想在 LaTeX 中绘制此图:
我需要同时在 x 和 y 中确定范围。我想显示两个指标在不同情景下全球变暖影响 (GWI) 与净现值 (NPV) 的关系。实际上是四种不同产品 (A、B、C、D) 的综合经济和环境图。这些值是理论计算的。该图应该显示产品的盈利能力以及它们在敏感度范围内的全球变暖影响 - 全部显示在一张图中。
这是我用来手动绘制值的代码:
\documentclass{scrbook}
\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{float}
\usepackage{pgfplots}
\pgfplotsset{compat=newest, scale only axis}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{axis}
[
extra x ticks = 0,
extra x tick labels = ,
extra x tick style = { grid = major },
height=7cm,
width=14cm,
ylabel=GWI,
xlabel=NPV,
legend pos=outer north east,
]
\addplot[CornflowerBlue,mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-24.8,9.34) += (0,1.2) -= (0,0.7)
(-19.0,9.34)+= (0,1.2) -= (0,0.7)
(-15.3,9.34) += (0,1.2) -= (0,0.7)
(218.4,9.34) += (0,1.2) -= (0,0.7)
(275.3,9.34) += (0,1.2) -= (0,0.7)
(309.7,9.34) += (0,1.2) -= (0,0.7)
(510.8,9.34) += (0,1.2) -= (0,0.7)
(629.0,9.34) += (0,1.2) -= (0,0.7)
(700.4,9.34) += (0,1.2) -= (0,0.7)
};
\addlegendentry{A}
\addplot[YellowGreen,mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-154.1,16.76) +-(0,2.2)
(-152.6,16.76) +-(0,2.2)
(-149.4,16.76) +-(0,2.2)
(93.80,16.76) +-(0,2.2)
(141.7,16.76) +-(0,2.2)
(170.9,16.76) +-(0,2.2)
(386.2,16.76) +-(0,2.2)
(495.4,16.76) +-(0,2.2)
(561.6,16.76) +-(0,2.2)
};
\addlegendentry{B}
\addplot[Goldenrod, mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-204.9,16.07) += (0,3.2) -= (0,2.0)
(-194.5,16.07) += (0,3.2) -= (0,2.0)
(-176.9,16.07) += (0,3.2) -= (0,2.0)
(66.40,16.07) += (0,3.2) -= (0,2.0)
(99.80,16.07) += (0,3.2) -= (0,2.0)
(120.2,16.07) += (0,3.2) -= (0,2.0)
(358.8,16.07) += (0,3.2) -= (0,2.0)
(453.5,16.07) += (0,3.2) -= (0,2.0)
(510.8,16.07) += (0,3.2) -= (0,2.0)
};
\addlegendentry{C}
\addplot[Lavender,mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-109.6,14.35) += (0,3.3) -= (0,1.8)
(-108.0,14.35) += (0,3.3) -= (0,1.8)
(-105.0,14.35) += (0,3.3) -= (0,1.8)
(138.3,14.35) += (0,3.3) -= (0,1.8)
(186.3,14.35) += (0,3.3) -= (0,1.8)
(215.5,14.35) += (0,3.3) -= (0,1.8)
(430.6,14.35) += (0,3.3) -= (0,1.8)
(540.0,14.35) += (0,3.3) -= (0,1.8)
(606.1,14.35) += (0,3.3) -= (0,1.8)
};
\addlegendentry{D}
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
答案1
..使用此代码:
\documentclass{scrbook}
\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{float}
\usepackage{pgfplots}
\pgfplotsset{compat=newest, scale only axis}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{axis}
[
extra x ticks = 0,
extra x tick labels = ,
extra x tick style = { grid = major },
height=7cm,
width=14cm,
ylabel=GWI,
xlabel=NPV,
legend pos=outer north east,
]
\addplot[CornflowerBlue,mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-24.8,9.34) += (0,1.2) -= (0,0.7)
(-19.0,9.34)+= (0,1.2) -= (0,0.7)
(-15.3,9.34) += (0,1.2) -= (0,0.7)
(218.4,9.34) += (0,1.2) -= (0,0.7)
(275.3,9.34) += (0,1.2) -= (0,0.7)
(309.7,9.34) += (0,1.2) -= (0,0.7)
(510.8,9.34) += (0,1.2) -= (0,0.7)
(629.0,9.34) += (0,1.2) -= (0,0.7)
(700.4,9.34) += (0,1.2) -= (0,0.7)
};
\addlegendentry{A}
\addplot[YellowGreen,mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-154.1,16.76) +-(0,2.2)
(-152.6,16.76) +-(0,2.2)
(-149.4,16.76) +-(0,2.2)
(93.80,16.76) +-(0,2.2)
(141.7,16.76) +-(0,2.2)
(170.9,16.76) +-(0,2.2)
(386.2,16.76) +-(0,2.2)
(495.4,16.76) +-(0,2.2)
(561.6,16.76) +-(0,2.2)
};
\addlegendentry{B}
\addplot[Goldenrod, mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-204.9,16.07) += (0,3.2) -= (0,2.0)
(-194.5,16.07) += (0,3.2) -= (0,2.0)
(-176.9,16.07) += (0,3.2) -= (0,2.0)
(66.40,16.07) += (0,3.2) -= (0,2.0)
(99.80,16.07) += (0,3.2) -= (0,2.0)
(120.2,16.07) += (0,3.2) -= (0,2.0)
(358.8,16.07) += (0,3.2) -= (0,2.0)
(453.5,16.07) += (0,3.2) -= (0,2.0)
(510.8,16.07) += (0,3.2) -= (0,2.0)
};
\addlegendentry{C}
\addplot[Lavender,mark=*,line width=1pt] plot[error bars/.cd,
y dir=both,y explicit,
error bar style={line width=1pt},
error mark options={
rotate=90,
mark size=2pt,
line width=1pt}
]
coordinates {
(-109.6,14.35) += (0,3.3) -= (0,1.8)
(-108.0,14.35) += (0,3.3) -= (0,1.8)
(-105.0,14.35) += (0,3.3) -= (0,1.8)
(138.3,14.35) += (0,3.3) -= (0,1.8)
(186.3,14.35) += (0,3.3) -= (0,1.8)
(215.5,14.35) += (0,3.3) -= (0,1.8)
(430.6,14.35) += (0,3.3) -= (0,1.8)
(540.0,14.35) += (0,3.3) -= (0,1.8)
(606.1,14.35) += (0,3.3) -= (0,1.8)
};
\addlegendentry{D}
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
为了获得相应透明颜色的市场区域,我为每个图添加了这个(这里是产品 A 的示例 - 蓝色图):
\fill[CornflowerBlue,opacity=0.3] (-24.8,8.64) rectangle (700.4,10.54);
x 值是最小和最大 NPV 值。y 值是具有正值和负值范围的相应 GWI 值。
注意:标记区域仅用于说明目的,不增加任何与内容相关的价值。