我使用以下代码
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{tkz-fct}
\usetikzlibrary{arrows, arrows.meta, positioning, calc, intersections, decorations.pathreplacing, decorations.pathmorphing, decorations.markings, shapes, shapes.misc, shapes.symbols, shapes.geometric, patterns, backgrounds, fadings, trees, shadows}
\begin{document}
\tikzset{pics/.cd,
curvea/.style n args={2}{code={
\node [red] at (#1,#2) (begin){}
([shift={(-90.:1.4cm)}]begin.center) node (beginclip){}
([shift={(0.:.2cm)}]begin.center) node (beginr){}
([shift={(30:4.cm)}]beginr.center) node (midtop){}
([shift={(-30:4.cm)}]midtop.center) node (end){}
([shift={(0.:.2cm)}]end.center) node (endr){}
([shift={(-90.:1cm)}]endr.center) node (endrclip){}
([shift={(0:.5cm)}]beginr.center) node (arrowl){}
([shift={(180:.5cm)}]end.center) node (arrowr){}
([shift={(180:2.46cm)}]midtop.center) node (midtopll){}
([shift={(0:2.46cm)}]midtop.center) node (midtoprr){}
([shift={(180:1.46cm)}]midtop.center) node (midtopl){}
([shift={(0:1.46cm)}]midtop.center) node (midtopr){}
;
}}}
\begin{frame}[t]
\frametitle{variation}
\begin{tikzpicture}[scale=.78, transform shape]
% Axis
\draw [thick](0,0) -- (14.5,0);
\draw [thick](0,0) -- (0,6.);
%Curve
\pic at (0,0) {curvea={1.64}{.28}};
\draw[red!40!white, very thick, fill=red!20!white] ([shift={(-170.:1.4cm)}]begin.center) to [out=10, in=-160, looseness=.68] (beginr.center) to [out=20, in=180, looseness=.6] ([shift={(90:2.6cm)}]midtop.center) node (midtopnewr){} to [out=0, in=150, looseness=.6] (end.center) to [out=-20, in=180, looseness=.68] ([shift={(-10.:1.4cm)}]endr.center);
\end{tikzpicture}
\end{frame}
\end{document}
绘制以下图形
如何修改此代码,以便可以填充曲线外部(而不是内部)的区域,如下图所示
答案1
添加边框线,使曲线外的区域成为封闭路径。
\begin{tikzpicture}[scale=.78, transform shape]
% Axis
\draw [thick] (0,0) -- (14.5,0);
\draw [thick] (0,0) -- (0,6.);
% Curve
\pic at (0,0) {curvea={1.64}{.28}};
\draw [red!40!white, very thick, fill=red!20!white] ([shift={(-170.:1.4cm)}]begin.center) to [out=10, in=-160, looseness=.68] (beginr.center) to [out=20, in=180, looseness=.6] ([shift={(90:2.6cm)}]midtop.center) node (midtopnewr){} to [out=0, in=150, looseness=.6] (end.center) to [out=-20, in=180, looseness=.68] ([shift={(-10.:1.4cm)}]endr.center) -- ++(0, 4.85) -- ++(-10, 0) -- cycle;
\end{tikzpicture}
答案2
在曲线前画一个填充的矩形:
\begin{tikzpicture}[scale=.78, transform shape]
% Axis
\draw [thick](0,0) -- (14.5,0);
\draw [thick](0,0) -- (0,6.);
%Curve
\pic at (0,0) {curvea={1.64}{.28}};
\filldraw[green] (0.1,0.05) rectangle (10.8,4.9);
\draw[red!40!white, very thick, fill=white] ([shift={(-170.:1.4cm)}]begin.center) to [out=10, in=-160, looseness=.68] (beginr.center) to [out=20, in=180, looseness=.6] ([shift={(90:2.6cm)}]midtop.center) node (midtopnewr){} to [out=0, in=150, looseness=.6] (end.center) to [out=-20, in=180, looseness=.68] ([shift={(-10.:1.4cm)}]endr.center);
\end{tikzpicture}