用颜色填充由 plot[smooth] 创建的区域

用颜色填充由 plot[smooth] 创建的区域

我想用某种颜色为图片的每个区域着色。Tikz 代码:

\begin{tikzpicture}
\node[draw=none] at (3.5,3) {\scriptsize \ldots};
\node[draw=none] at (0.42,1.47) [text width=1cm] {\scriptsize $a.0 + 0$ $0 + a.0$ $a.0$ $a.0 \mid 0$ \ldots};
\node[draw=none] at (0.5,4.5) [text width=1.5cm] {\scriptsize $b.a.0$ $b.(a.0 + 0)$ \ldots};
\draw[preaction={draw, ultra thick, double distance=0pt}]
plot[smooth cycle]
coordinates{
  (0,0) (0,6) (6,6) (6,0)
};

\draw[preaction={draw, ultra thick, double distance=0pt}]
plot[smooth]
coordinates{
  (1.5,6.5) (1.5,4.5) (-0.6,2)
};

\draw[preaction={draw, ultra thick, double distance=0pt}]
plot[smooth]
coordinates{
  (1.5,4.5) (2,3) (1.5,-0.5)
};
\end{tikzpicture}

答案1

这是一种使用绘制顺序和剪辑的方法。

首先,从最大到最小填充区域颜色。将区域稍微延伸一点,并裁剪外边界,

\begin{tikzpicture}

% make outer plot as a command because it is used often during clipping
\newcommand{\outline}[0]{%
plot[smooth cycle]%
coordinates{%
  (0,0) (0,6) (6,6) (6,0)%
}}

%fill 
\fill[green] 
\outline;

\begin{scope}
    \clip \outline;
    \fill[blue] (1.5,-0.5) -- (-0.6,-0.5) -- (-0.6,2) -- (1.5,4.5) % extend the area to the corners
        plot[smooth] coordinates{ (1.5,4.5) (2,3) (1.5,-0.5) };
\end{scope}

\begin{scope}
    \clip \outline;
    \fill[red] (1.5,6.5) -- (-1.5,6.5) -- (-0.6,2)  plot[smooth] coordinates{ (1.5,6.5) (1.5,4.5) (-0.6,2) };
\end{scope}

其次,在顶部画线。我不确定后置动作和双倍距离应该是多少,但如果您只想使线条比超粗更粗,请使用line width将其设置为任意粗细:

% draw
\draw[line width=2.5pt]
\outline;

\draw[line width=2.5pt]
plot[smooth] coordinates{ (1.5,6.5) (1.5,4.5) (-0.6,2) };

\draw[line width=2.5pt, fill=blue]
plot[smooth] coordinates{ (1.5,4.5) (2,3) (1.5,-0.5) };

\node[draw=none] at (3.5,3) {\scriptsize \ldots};
\node[draw=none] at (0.42,1.47) [text width=1cm] {\scriptsize $a.0 + 0$ $0 + a.0$ $a.0$ $a.0 \mid 0$ \ldots};
\node[draw=none] at (0.5,4.5) [text width=1.5cm] {\scriptsize $b.a.0$ $b.(a.0 + 0)$ \ldots};

\end{tikzpicture}

结果: 在此处输入图片描述

相关内容