如何绘制此类图表:带有垂直误差指示器的线图

如何绘制此类图表:带有垂直误差指示器的线图

我想在 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 值。 在此处输入图片描述 注意:标记区域仅用于说明目的,不增加任何与内容相关的价值。

相关内容