用阴影标出由某些坐标限定的图表的上界

用阴影标出由某些坐标限定的图表的上界

我想用阴影标记下面给出代码的图表的上边界。非常感谢您的帮助。我没有特定的函数,而是有由线连接的特定坐标。我很想用阴影标记由这些坐标限定的上边界区域。

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.7]
    \begin{axis}[
    xlabel={Policy Importance ($D$)},
    ylabel={Optimal voting Rule $r_{1}*(D)$},
    xmin=1, xmax=100,
    ymin=50, ymax=100,
    xtick={1,5, 10, 20, 30, 45, 55,70, 80, 90, 100},
    ytick={50,67,76,81,86,91,96,100},
    legend pos=outer north east,
    ymajorgrids=true,
    xmajorgrids=true,
    grid style=dashed,
    ]
    \addplot[
    color=blue,
    mark=*,
    ]
    coordinates {
        (1,51)(2,67)(3,76)(4,81)(6,86)(10,91)(20,96)(50,99)(100,100)
    };
    \end{axis}
    \end{tikzpicture}
\caption{Optimal supermajority rule as a function of policy
importance for continuous decisions.} 
\end{figure}

答案1

对于这种特殊情况,由于区域受轴的限制,因此您可以使用额外的绘图指令。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
xlabel={Policy Importance ($D$)},
ylabel={Optimal voting Rule $r_{1}*(D)$},
xmin=1, xmax=100,
ymin=50, ymax=100,
xtick={1,5, 10, 20, 30, 45, 55,70, 80, 90, 100},
ytick={50,67,76,81,86,91,96,100},
legend pos=outer north east,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
]
\addplot[shade,
top color=blue!10,
bottom color=blue,
draw=blue,
mark=*,
]
coordinates {
    (1,51)(2,67)(3,76)(4,81)(6,86)(10,91)(20,96)(50,99)(100,100)
} -| (rel axis cs:0,0);
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容