编辑

编辑

我正在使用 TikZ 包来显示一组复数,其中我想要的数位于半径为 2 的圆的外侧,而半径为 1 的圆不在集合中: 在此处输入图片描述

我想让内圈为白色,轴完全显示出来,但我不知道该怎么做。我使用两个半透明填充的圆圈。有什么方法可以只填充外部吗?相关代码如下。

(这是我获得大部分代码的地方:在复平面上画一个圆。

\begin{tikzpicture}
    \begin{scope}[thick,font=\scriptsize][set layers]
    \draw [->] (-4,0) -- (4,0) node [above left]  {$\Re\{z\}$};
    \draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
    \iffalse% Single
    \draw (1,-3pt) -- (1,3pt)   node [above] {$1$};
    \draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
    \draw (-3pt,1) -- (3pt,1)   node [right] {$i$};
    \draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
    \else% Multiple
    \foreach \n in {-3,...,-1,1,2,...,3}{%
        \draw (\n,-3pt) -- (\n,3pt)   node [above] {$\n$};
        \draw (-3pt,\n) -- (3pt,\n)   node [right] {$\n i$};
    }
    \fi
    \end{scope}
    \draw[solid] (0,-1) circle (1);
    \draw[solid] (0,-1) circle (2);
    \path [draw=none,fill=gray, fill opacity = 0.1] (0,-1) circle (2);
    \path [draw=none,fill=white, fill opacity = 0.7] (0,-1) circle (1);
    \node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
\end{tikzpicture}

答案1

您可以使用不同的填充规则,即even odd rule填充每个偶数封闭区域。

因此,如果您使用以下线而不是两个不同的圆圈,您将得到一个甜甜圈填充;

\path [draw=none,fill=gray, fill opacity = 0.1,even odd rule] (0,-1) circle (2) (0,-1) circle (1);

在此处输入图片描述

答案2

在这种特殊情况下,您可以简单地更改绘图顺序,即先绘制圆圈:

\documentclass[tikz]{standalone}
\usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}
        \path [draw=none,fill=gray, fill opacity = 0.1] (0,-1) circle (2);
    \path [draw=none,fill=white] (0,-1) circle (1);
    \begin{scope}[thick,font=\scriptsize][set layers]
    \draw [->] (-4,0) -- (4,0) node [above left]  {$\Re\{z\}$};
    \draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
    \iffalse% Single
    \draw (1,-3pt) -- (1,3pt)   node [above] {$1$};
    \draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
    \draw (-3pt,1) -- (3pt,1)   node [right] {$i$};
    \draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
    \else% Multiple
    \foreach \n in {-3,...,-1,1,2,...,3}{%
        \draw (\n,-3pt) -- (\n,3pt)   node [above] {$\n$};
        \draw (-3pt,\n) -- (3pt,\n)   node [right] {$\n i$};
    }
    \fi
    \end{scope}
    \draw[solid] (0,-1) circle (1);
    \draw[solid] (0,-1) circle (2);
%    \path [draw=none,fill=gray, fill opacity = 0.1] (0,-1) circle (2);
%    \path [draw=none,fill=white, fill opacity = 0.7] (0,-1) circle (1);
    \node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

使用‘奇偶规则’:

\documentclass[tikz]{standalone}
\usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}
    \begin{scope}[thick,font=\scriptsize][set layers]
    \draw [->] (-4,0) -- (4,0) node [above left]  {$\Re\{z\}$};
    \draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
    \iffalse% Single
    \draw (1,-3pt) -- (1,3pt)   node [above] {$1$};
    \draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
    \draw (-3pt,1) -- (3pt,1)   node [right] {$i$};
    \draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
    \else% Multiple
    \foreach \n in {-3,...,-1,1,2,...,3}{%
        \draw (\n,-3pt) -- (\n,3pt)   node [above] {$\n$};
        \draw (-3pt,\n) -- (3pt,\n)   node [right] {$\n i$};
    }
    \fi
    \end{scope}
    \draw[solid] (0,-1) circle (1);
    \draw[solid] (0,-1) circle (2);
    \path [draw=none, fill=gray, even odd rule, fill opacity = 0.1] (0,-1) circle (2) (0,-1) circle (1);
    \node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
\end{tikzpicture}
\end{document}

偶数奇数填充

编辑

由于 percusse 使用奇偶规则解决方案速度更快(但我注意到,它没有提供完整的 MWE),因此,如果您希望填充内圆但仍希望轴位于顶部,可以使用以下解决方案。此解决方案使用库来backgrounds填充内圆在后面图片的其余部分,以便轴保持在顶部。

\documentclass[tikz]{standalone}
\usepackage{amsfonts}
\usetikzlibrary{backgrounds}
\begin{document}
  \begin{tikzpicture}
    \begin{scope}[thick,font=\scriptsize][set layers]
      \draw [->] (-4,0) -- (4,0) node [above left]  {$\Re\{z\}$};
      \draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
      \iffalse % Single
      \draw (1,-3pt) -- (1,3pt)   node [above] {$1$};
      \draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
      \draw (-3pt,1) -- (3pt,1)   node [right] {$i$};
      \draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
      \else% Multiple
      \foreach \n in {-3,...,-1,1,2,...,3}{%
        \draw (\n,-3pt) -- (\n,3pt)   node [above] {$\n$};
        \draw (-3pt,\n) -- (3pt,\n)   node [right] {$\n i$};
      }
      \fi
    \end{scope}
    \draw[solid] (0,-1) circle (1);
    \draw[solid] (0,-1) circle (2);
    \path [fill=gray, fill opacity = 0.1] (0,-1) circle (2);
    \begin{scope}[on background layer]
        \path [fill=white, fill opacity=.7] (0,-1) circle (1);
    \end{scope}
    \node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
  \end{tikzpicture}
\end{document}

使用背景库回答另一个问题

答案4

使用 MetaPost(通过 LuaLaTeX)完成,可能会引起人们的兴趣。

借助Metafun格式进行透明填充:

fill ring withcolor transparent(1, 0.1, \mpcolor{gray});

环本身是通过将其中一个圆附加到反转的另一个圆上而创建的:

ring = circle1 -- reverse circle2 -- cycle;

(当然,更简单快捷的方法是填充最大的圆圈并取消填充最小的圆圈,但我发现创建这个环形路径并直接填充它很有趣。)

完整代码:

\documentclass[12pt]{standalone}
\usepackage{amssymb, xcolor}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
u = 1.5cm; xmax = 3.9 = ymax = -ymin = -xmin; len = 6bp;
path circle[], ring;
circle1 = fullcircle scaled 2u shifted (0, -u);
circle2 = fullcircle scaled 4u shifted (0, -u);
ring = circle1 -- reverse circle2 -- cycle;
labeloffset := 6bp;
beginfig(1);
    for i = ceiling(xmin) upto floor(xmax):
        draw (i*u, -0.5len) -- (i*u, 0.5len); 
        if i <> 0: label.top("$" & decimal i & "$", (i*u, 0)); fi
    endfor
    for j = ceiling(ymin) upto floor(ymax):
        draw (-0.5len, j*u) -- (0.5len, j*u); 
        if j <> 0: label.rt("$" & decimal j & "i$", (0, j*u)); fi
    endfor
    drawarrow (xmin*u, 0) -- (xmax*u, 0); label.top("$\Re\{ z \}$", (xmax*u, 0));
    drawarrow (0, ymin*u) -- (0, ymax*u); label.rt("$\Im\{ z \}$", (0, ymax*u));
    fill ring withcolor transparent(1, 0.1, \mpcolor{gray});
    for i = 1,2: draw circle[i]; endfor
    label.urt("$A = \{z \in \mathbb{C}: 1 \leqslant |z-(-i)| \leqslant2 \}$", 
        point 1.5 of circle2);
endfig;
\end{mplibcode}
\end{document}

在此处输入图片描述

相关内容