将阴影区域剪裁至曲线边界

将阴影区域剪裁至曲线边界

我试图绘制下面的图表,但未能实现。

在此处输入图片描述

这段代码有什么问题

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc, backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}
\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);
\foreach \y [evaluate=\y as \aff using int(\y*10)]in {0,2,4,...,10}{ \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);}
\foreach \x [evaluate=\x as \aff using int(\x*10)]in {0,2,4,...,10}{ \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);}
\draw [very thick, blue, looseness=.9] (0,0) to [out=15, in=-110] node [pos=.0] (ao) {} node [pos=.08] (aw){} node [pos=.146] (ah) {} node [pos=.24] (af) {} node [pos=.306] (av) {} node [pos=.4] (ax) {} node [pos=.484] (as) {} node [pos=.58] (ag) {} node [pos=.704] (an) {} node [pos=.8] (at) {} node [pos=1.] (aa) {} (\incrmntx*10,\incrmnty*10);
\draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
\path[clip] (0,0)  to [out=15, in=-110] (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\draw [thick, black!80!white, fill=black!65!white] (aa.center) node [black, xshift=.36cm, yshift=-3.cm] {} |- (aa.center|-0,0) -- (0,0) --  (aa.center);
\draw [thick, black!80!white, fill=black!60!white] (at.center) node [black, xshift=.36cm, yshift=-3.cm] {$\bf A_10$} |- (at.center|-0,0) -- (0,0) --  (at.center) -| (at.center-|0,0);
\draw [thick, black!80!white, fill=black!55!white] (an.center) node [black, xshift=.28cm, yshift=-2.4cm] {$\bf A_9$} |- (an.center|-0,0) -- (0,0) --  (an.center) -| (an.center-|0,0);
\draw [thick, black!80!white, fill=black!50!white] (ag.center) node [black, xshift=.28cm, yshift=-2.cm] {$\bf A_8$} |- (ag.center|-0,0) -- (0,0) --  (ag.center) -| (ag.center-|0,0);
\draw [thick, black!80!white, fill=black!45!white] (as.center) node [black, xshift=.28cm, yshift=-1.46cm] {$\bf A_7$} |- (as.center|-0,0) -- (0,0) --  (as.center) -| (as.center-|0,0);
\draw [thick, black!80!white, fill=black!40!white] (ax.center) node [black, xshift=.28cm, yshift=-1.2cm] {$\bf A_6$} |- (ax.center|-0,0)-- (0,0) --   (ax.center) -| (ax.center-|0,0);
\draw [thick, black!80!white, fill=black!35!white] (av.center) node [black, xshift=.28cm, yshift=-.9cm] {$\bf A_5$} |- (av.center|-0,0) -- (0,0) --  (av.center) -| (av.center-|0,0);
\draw [thick, black!80!white, fill=black!30!white] (af.center) node [black, xshift=.28cm, yshift=-.68cm] {$\bf A_4$} |- (af.center|-0,0)-- (0,0) --   (af.center) -| (af.center-|0,0);
\draw [thick, black!80!white, fill=black!25!white] (ah.center) node [black, xshift=.28cm, yshift=-.4cm] {$\bf A_3$} |- (ah.center|-0,0) -- (0,0) --  (ah.center) -| (ah.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (aw.center) node [black, xshift=.28cm, yshift=-.16cm] {$\bf A_2$} |- (aw.center|-0,0) -- (0,0) -- (aw.center) -| (aw.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (ao.center) node [black, xshift=.8cm, yshift=0cm] {$\bf A_1$} |- (ao.center|-0,0) -- (0,0) -- (ao.center) -| (ao.center-|0,0);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

它生成了以下绘图

在此处输入图片描述

应满足以下意见

  1. 阴影区域应限制在蓝色曲线以下,即 x 轴范围内。

  2. 蓝色曲线上的节点与位置 (0,0) 之间不应有连接线。

  3. 与 y60 和 y20 的关系不正确。

答案1

与 Martin Scharrer 的回答类似,但使用循环使代码更短。 (是的,looseness剪辑路径中缺少。)

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}
\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);
\foreach \y [evaluate=\y as \aff using int(\y*10)]in {0,2,4,...,10}
{ \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);}
\foreach \x [evaluate=\x as \aff using int(\x*10)]in {0,2,4,...,10}
{ \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);}
\draw [very thick, blue] (0,0) to [out=15, in=-110, looseness=.9] 
coordinate [pos=.0] (ao)  coordinate [pos=.08] (aw) coordinate [pos=.146] (ah)  
coordinate [pos=.24] (af)  coordinate [pos=.306] (av)  coordinate [pos=.4] (ax)  
coordinate [pos=.484] (as)  coordinate [pos=.58] (ag)  coordinate [pos=.704] (an)  
coordinate [pos=.8] (at)  coordinate [pos=1.] (aa)  (\incrmntx*10,\incrmnty*10);
\draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\path[clip,postaction={draw,green,line width=1mm}] (0,0)  
to [out=15, in=-110, looseness=.9] (\incrmntx*10,\incrmnty*10) |- cycle;
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(12-\Y)}] in {aa,at,an,ag,as,ax,av,af,ah,aw,ao}
{\pgfmathtruncatemacro{\fullness}{70-5*\Y}
\draw [thick, black!80!white, fill=black!\fullness!white]
(0,0) -- (\X.center) |-  cycle ;}
\end{scope}
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(11-\Y)}] in {at,an,ag,as,ax,av,af,ah,aw,ao}
\draw [thick] (\X.center|-0,0) |- (\X.center-| (0,0)node[pos=0.25,right]{$\boldsymbol{A_{\Z}}$};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

答案2

您需要将剪切路径放入范围之内,而不是范围之前,然后使用 eg|- cycle或类似符号关闭剪切路径。此外,您还需要与实际线相同的参数。looseness缺少值。

这解决了您列表中的第 1 点和第 2 点。我不明白您说的第 3 点是什么意思。

我还修复了你的A_10需要写为的A_{10}

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc, backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}

\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);

\foreach \y [evaluate=\y as \aff using int(\y*10)] in {0,2,4,...,10}{
    \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);
}

\foreach \x [evaluate=\x as \aff using int(\x*10)] in {0,2,4,...,10}{
    \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);
}

\draw [very thick, blue, looseness=.9] (0,0) to [out=15, in=-110] 
    node [pos=.0] (ao) {}
    node [pos=.08] (aw){}
    node [pos=.146] (ah) {}
    node [pos=.24] (af) {}
    node [pos=.306] (av) {}
    node [pos=.4] (ax) {}
    node [pos=.484] (as) {}
    node [pos=.58] (ag) {}
    node [pos=.704] (an) {}
    node [pos=.8] (at) {}
    node [pos=1.] (aa) {}
    (\incrmntx*10,\incrmnty*10);

\draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\path [clip, looseness=.9] (0,0) to [out=15, in=-110] (\incrmntx*10,\incrmnty*10) |- (0, -1) -- cycle;
\draw [thick, black!80!white, fill=green!65!white] (aa.center) node [black, xshift=.36cm, yshift=-3.cm] {X} |- (aa.center|-0,0) -- (0,0) --  (aa.center);
\draw [thick, black!80!white, fill=black!60!white] (at.center) node [black, xshift=.36cm, yshift=-3.cm] {$\bf A_{10}$} |- (at.center|-0,0) -- (0,0) --  (at.center) -| (at.center-|0,0);
\draw [thick, black!80!white, fill=black!55!white] (an.center) node [black, xshift=.28cm, yshift=-2.4cm] {$\bf A_9$} |- (an.center|-0,0) -- (0,0) --  (an.center) -| (an.center-|0,0);
\draw [thick, black!80!white, fill=black!50!white] (ag.center) node [black, xshift=.28cm, yshift=-2.cm] {$\bf A_8$} |- (ag.center|-0,0) -- (0,0) --  (ag.center) -| (ag.center-|0,0);
\draw [thick, black!80!white, fill=black!45!white] (as.center) node [black, xshift=.28cm, yshift=-1.46cm] {$\bf A_7$} |- (as.center|-0,0) -- (0,0) --  (as.center) -| (as.center-|0,0);
\draw [thick, black!80!white, fill=black!40!white] (ax.center) node [black, xshift=.28cm, yshift=-1.2cm] {$\bf A_6$} |- (ax.center|-0,0)-- (0,0) --   (ax.center) -| (ax.center-|0,0);
\draw [thick, black!80!white, fill=black!35!white] (av.center) node [black, xshift=.28cm, yshift=-.9cm] {$\bf A_5$} |- (av.center|-0,0) -- (0,0) --  (av.center) -| (av.center-|0,0);
\draw [thick, black!80!white, fill=black!30!white] (af.center) node [black, xshift=.28cm, yshift=-.68cm] {$\bf A_4$} |- (af.center|-0,0)-- (0,0) --   (af.center) -| (af.center-|0,0);
\draw [thick, black!80!white, fill=black!25!white] (ah.center) node [black, xshift=.28cm, yshift=-.4cm] {$\bf A_3$} |- (ah.center|-0,0) -- (0,0) --  (ah.center) -| (ah.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (aw.center) node [black, xshift=.28cm, yshift=-.16cm] {$\bf A_2$} |- (aw.center|-0,0) -- (0,0) -- (aw.center) -| (aw.center-|0,0);
\draw [thick, black!80!white, fill=black!20!white] (ao.center) node [black, xshift=.8cm, yshift=0cm] {$\bf A_1$} |- (ao.center|-0,0) -- (0,0) -- (ao.center) -| (ao.center-|0,0);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

答案3

我得去上班了,如果你需要的话我下午再来解释代码。抱歉。

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc, backgrounds}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\pgfmathsetmacro{\incrmnty}{.86}
\pgfmathsetmacro{\incrmntx}{.86}
\draw [thick](0,0) -- (\incrmntx*10,0);
\draw [thick](0,0) -- (0,\incrmnty*10);
\foreach \y [evaluate=\y as \aff using int(\y*10)]in {0,2,4,...,10}{ \draw [black] (0,\incrmnty*\y) node [left, xshift=-.1cm] {\aff} -- +(180:.12);}
\foreach \x [evaluate=\x as \aff using int(\x*10)]in {0,2,4,...,10}{
            \draw [black] (\incrmnty*\x,0) node [below, yshift=-.25cm] {\aff} -- +(-90:\incrmntx*.2);
            }
            \draw [very thick, blue, looseness=.9] (0,0) to [out=15, in=-110] node [pos=.0] (ao) {} node [pos=.08] (aw){} node [pos=.146] (ah) {} node [pos=.24] (af) {} node [pos=.306] (av) {} node [pos=.4] (ax) {} node [pos=.484] (as) {} node [pos=.58] (ag) {} node [pos=.704] (an) {} node [pos=.8] (at) {at} node [pos=1.] (aa) {} (\incrmntx*10,\incrmnty*10);
            \draw [very thick, red!70!black, looseness=1] (0,0) -- (\incrmntx*10,\incrmnty*10);
            \path[clip] (0,0)  to [out=15, in=-110] (\incrmntx*10,\incrmnty*10);
\begin{scope}[on background layer]
\draw [thick, black!80!white, fill=black!65!white] (aa.center |- 0,0)--(aa.center)  --(at.center) |- (at.center |- 0,0) -- cycle;
\draw [thick, black!80!white, fill=black!60!white] (at.center) node [black, xshift=.36cm, yshift=-3.cm] {$\bf A_10$} --(an.center) |-(at.center |- 0,0) --cycle;
\draw [thick, black!80!white, fill=black!55!white] (an.center) node [black, xshift=.28cm, yshift=-2.4cm] {$\bf A_9$} -- (ag.center)|- (an.center|- 0,0) -- cycle;
\draw [thick, black!80!white, fill=black!50!white] (ag.center) node [black, xshift=.28cm, yshift=-2.cm] {$\bf A_8$} --(as.center) |- (ag.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!45!white] (as.center) node [black, xshift=.28cm, yshift=-1.46cm] {$\bf A_7$} --(ax.center)|- (as.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!40!white] (ax.center) node [black, xshift=.28cm, yshift=-1.2cm] {$\bf A_6$} -- (av.center)|- (ax.center|-0,0)-- cycle;
\draw [thick, black!80!white, fill=black!35!white] (av.center) node [black, xshift=.28cm, yshift=-.9cm] {$\bf A_5$} --(af.center)|- (av.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!30!white] (af.center) node [black, xshift=.28cm, yshift=-.68cm] {$\bf A_4$} --(ah.center)|- (af.center|-0,0)-- cycle;
\draw [thick, black!80!white, fill=black!25!white] (ah.center) node [black, xshift=.28cm, yshift=-.4cm] {$\bf A_3$} --(aw.center)|- (ah.center|-0,0) -- cycle;
\draw [thick, black!80!white, fill=black!20!white] (aw.center) node [black, xshift=.28cm, yshift=-.16cm] {$\bf A_2$} --(ao.center)|- (aw.center|-0,0) -- cycle;
%\draw [thick, black!80!white, fill=black!20!white] (ao.center) node [black, xshift=.8cm, yshift=0cm] {$\bf A_1$} |- (ao.center|-0,0) -- (0,0) -- (ao.center) -| (ao.center-|0,0);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

截屏

相关内容