我已经创建了一个非常小的 tikzpicture(见下文),现在想要为两条曲线交点下方的区域着色。
如何实现这一点?
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{patterns}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\draw plot [smooth, tension=2] coordinates { (0,0) (1,2) (2,0) };
\draw plot [smooth, tension=2] coordinates { (1.5,0) (2.5,2) (3.5,0) };
\end{tikzpicture}
\end{figure}
\end{document}
答案1
对于您的简单示例,一个简单的方法是填充整个矩形并消除clip
曲线之外的所有内容。
输出
代码
\documentclass[tikz, border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope} %under the left curve
\clip plot [smooth, tension=2] coordinates { (0,0) (1,2) (2,0) };
\path [fill=green!30] (0,0) rectangle (5,5) ;
\end{scope}
\begin{scope} %under the right curve
\clip plot [smooth, tension=2] coordinates { (1.5,0) (2.5,2) (3.5,0) };
\path [fill=blue!30] (0,0) rectangle (5,5) ;
\end{scope}
\begin{scope} %under both curves
\clip plot [smooth, tension=2] coordinates { (0,0) (1,2) (2,0) };
\clip plot [smooth, tension=2] coordinates { (1.5,0) (2.5,2) (3.5,0) };
\path [fill=red!30] (0,0) rectangle (5,5) ;
\end{scope}
% and now, we draw the curves :
\draw plot [smooth, tension=2] coordinates { (0,0) (1,2) (2,0) };
\draw plot [smooth, tension=2] coordinates { (1.5,0) (2.5,2) (3.5,0) };
\end{tikzpicture}
\end{document}