我有这段代码,我想在 A 和 B 之间填充,但我做不到。我认为 \tikzfillbetween 有一个专门打包的,但我不知道。
\begin{minipage}{5.8cm}
\begin{figure}[H]
\begin{center}
\scalebox{.7}{
\begin{tikzpicture}[thick,simple/.style={fill=black,inner sep=.4mm,circle,color=black, minimum size=0mm}]
\draw[ very thick,->] (-.5,0) -- (8,0) node[right] {$X$};
\draw[very thick,->] (0,-.5) -- (0,5) node[above] {$Y$};
\draw[ very thick,dashed, name path=A] (1.5,0) -- (1.5,4.3) node[right] {};
\draw[ very thick,dashed, name path=B] (6.5,0) -- (6.5,4) node[right] {};
\node at(1.5,-.3){$a$};
\node at(6.5,-.3){$b$};
\node at(5,4){$f$};
\draw [very thick] (1,3.5) .. controls (1.7,4.7) .. (2.5,4.5);
\draw [very thick] (2.5,4.5) .. controls (5,2.5) .. (7,4.5);
\tikzfillbetween[of=A and B]{line width=0pt,pattern=north east lines,};
\end{tikzpicture} }
\end{center}
\end{figure}
\end{minipage}
\begin{minipage}{8cm}
\begin{flushleft}
$s=\int_{a}^{b}f(x)dx
$
\end{flushleft}
\end{minipage}
答案1
您不需要fillbetween
,至少如果您知道曲线或点a
和的坐标b
。例如,使用近似(且平滑)曲线,您可以得到:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns}
\tikzset
{% example function:
declare function={f(\x)=0.1*(\x-4)^3-0.7*(\x-4)+4;}
}
\begin{document}
\begin{tikzpicture}[thick]
\draw[very thick,->] (-0.5,0) -- (8,0) node[right] {$X$};
\draw[very thick,->] (0,-0.5) -- (0,5) node[above] {$Y$};
\fill[pattern=north west lines] (1.5,0) -- (1.5,{f(1.5)}) -- plot [domain=1.5:6.5,samples=61] (\x,{f(\x)}) -- (6.5,0) -- cycle;
\draw[very thick,dashed] (1.5,0) node[below] {\strut$a$} -- (1.5,{f(1.5)});
\draw[very thick,dashed] (6.5,0) node[below] {\strut$b$} -- (6.5,{f(6.5)});
\node at(5,4){$f$};
\draw[very thick] plot[domain=1:7,samples=71] (\x,{f(\x)});
\end{tikzpicture}
\end{document}