以某些座標界定的圖的上限進行著色

以某些座標界定的圖的上限進行著色

我想對下面給出的程式碼的圖表的上限進行著色。非常感謝您的幫忙。我沒有特定的功能,而是有透過線連接的特定座標。我很想對這些座標所界定的上部區域進行著色。

\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}

在此輸入影像描述

相關內容