如何繪製面積圖

如何繪製面積圖

我想畫面積圖,像這樣

在此輸入影像描述 我不知道如何用顏色填滿該區域,這就是我所擁有的

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{xcolor}
\pgfplotsset{compat=1.8}


\makeatletter
\let\percent\@percentchar
\makeatother

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
        %title = {Distinctive SIFT features vs. Image resolution},
        xlabel= X LABEL HERE, 
        ylabel= {Y LABEL HERE},
        enlarge x limits=0.1,
        legend style={
                at={(0.5,-0.15)},               
                anchor=north,legend columns=-1
        },
        width=12.8cm,
        height=8cm,
        point meta={x*100},
        symbolic x coords={100\percent, 90\percent, 79\percent, 69\percent, 60\percent, 50\percent, 39\percent, 30\percent, 20\percent},
        %grid=major
]
% Median
\addplot coordinates {
(100\percent, 7218) (90\percent, 6075) (79\percent, 4021) (69\percent, 2906) (60\percent, 1861) (50\percent, 768) (39\percent, 451) (30\percent, 317) (20\percent, 164)};

\end{axis}
\end{tikzpicture}

\end{center}
\end{document}

在此輸入影像描述

答案1

使用\closedcycle並指定填滿顏色。要獲得從上到下的漸變,您可以指定top color=bottom color=。對於從左到右的漸變,您指定left color=right color

在此輸入影像描述

筆記:

  • 我還進行了更改\addplot\addplot+以便將該fill選項附加到現有選項中。

代碼:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{xcolor}
\pgfplotsset{compat=1.8}


\makeatletter
\let\percent\@percentchar
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[
        %title = {Distinctive SIFT features vs. Image resolution},
        xlabel= X LABEL HERE, 
        ylabel= {Y LABEL HERE},
        enlarge x limits=0.1,
        legend style={
                at={(0.5,-0.15)},               
                anchor=north,legend columns=-1
        },
        width=12.8cm,
        height=8cm,
        point meta={x*100},
        symbolic x coords={100\percent, 90\percent, 79\percent, 69\percent, 60\percent, 50\percent, 39\percent, 30\percent, 20\percent},
        %grid=major
]
% Median
\addplot+  [left color=green, right color=red] coordinates {
(100\percent, 7218) (90\percent, 6075) (79\percent, 4021) (69\percent, 2906) (60\percent, 1861) (50\percent, 768) (39\percent, 451) (30\percent, 317) (20\percent, 164)} \closedcycle;

\end{axis}
\end{tikzpicture}
\end{document}

相關內容