圆形和椭圆形周围的阴影

圆形和椭圆形周围的阴影

我有一个椭圆形内的圆圈,我想在圆圈内(可以通过绘制实心圆圈来完成)和椭圆形外添加阴影。

我正在使用 tikz axis 包来绘制形状,并尝试使用 shade between 包来做阴影。我并不想保持这种方式,但我不想弄乱包设置。可能有一种方法可以使用奇偶规则,但我对此没有太多的练习。

这是我目前得到的图表(显然它不正确):

\documentclass[border=10pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz,pgfplots}     %for graphics
\pgfplotsset{compat = newest}     %to run newest version
\usepgfplotslibrary{fillbetween}
\begin{document}
\pagestyle{empty}

\begin{tikzpicture}
\begin{axis}[
  xmin=-6, xmax=6, ymin=-6, ymax=6,
  axis lines=middle,
  ticklabel style={font=\tiny},
   xtick = {-5,-4,...,5},
  ytick = {-5,-4,...,5},
  xlabel = \(x\),
  ylabel = \(y\),
    legend style={legend pos=north east,font=\tiny}
]

\addplot[name path = A,
   domain=-pi:pi,
   samples=200]({5*sin(deg(x))}, {3*cos(deg(x))});
\addlegendentry{\(\frac{x^{2}}{25} + \frac{y^{2}}{9} = 1\)}

\addplot[name path = B,
   domain=-pi:pi,
   samples=200]({3*sin(deg(x))}, {3*cos(deg(x))});
\addlegendentry{\(x^{2} + y^{2} = 9\)}

\path[name path = C] (-6,-6) -- (6,-6);

\path[name path = D] (-6,6) -- (6,6);
    
    \addplot[only marks,black] coordinates {(0,3) (0,-3)};
    
    \addplot[blue!70,opacity=0.4] fill between  [of=A and C];
\end{axis}
\end{tikzpicture}
\end{document}

答案1

这就是你想要实现的目标吗

我只添加了一行

\addplot[blue!70,opacity=0.4,even odd rule] fill between [of=B and C];

还删除了行

\path[name path = D] (-6,-6) -- (6,-6);

因为它是name path= C

平均能量损失

\documentclass[border=10pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz,pgfplots}     %for graphics
\pgfplotsset{compat = newest}     %to run newest version
\usepgfplotslibrary{fillbetween}
\begin{document}
    \pagestyle{empty}
    
    \begin{tikzpicture}
        \begin{axis}[
            xmin=-6, xmax=6, ymin=-6, ymax=6,
            axis lines=middle,
            ticklabel style={font=\tiny},
            xtick = {-5,-4,...,5},
            ytick = {-5,-4,...,5},
            xlabel = \(x\),
            ylabel = \(y\),
            legend style={legend pos=north east,font=\tiny}
            ]
            
            \addplot[name path = A,
            domain=-pi:pi,
            samples=200]({5*sin(deg(x))}, {3*cos(deg(x))});
            \addlegendentry{\(\frac{x^{2}}{25} + \frac{y^{2}}{9} = 1\)}
            
            \addplot[name path = B,
            domain=-pi:pi,
            samples=200]({3*sin(deg(x))}, {3*cos(deg(x))});
            \addlegendentry{\(x^{2} + y^{2} = 9\)}
            
            \path[name path = C] (-6,-6) -- (6,-6);
            
            \addplot[only marks,black] coordinates {(0,3) (0,-3)};
            
            \addplot[blue!70,opacity=0.4,even odd rule] fill between  [of=B and C];
        \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

编辑

您还可以path C通过将其定义为来将其简化为点源

\path[name path = C] (0,0) -- (0,0);

然后输出将减少到只有椭圆和圆

平均能量损失

\documentclass[border=10pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz,pgfplots}     %for graphics
\pgfplotsset{compat = newest}     %to run newest version
\usepgfplotslibrary{fillbetween}
\begin{document}
    \pagestyle{empty}
    
    \begin{tikzpicture}
        \begin{axis}[
            xmin=-6, xmax=6, ymin=-6, ymax=6,
            axis lines=middle,
            ticklabel style={font=\tiny},
            xtick = {-5,-4,...,5},
            ytick = {-5,-4,...,5},
            xlabel = \(x\),
            ylabel = \(y\),
            legend style={legend pos=north east,font=\tiny}
            ]
            
            \addplot[name path = A,
            domain=-pi:pi,
            samples=200]({5*sin(deg(x))}, {3*cos(deg(x))});
            \addlegendentry{\(\frac{x^{2}}{25} + \frac{y^{2}}{9} = 1\)}
            
            \addplot[name path = B,
            domain=-pi:pi,
            samples=200]({3*sin(deg(x))}, {3*cos(deg(x))});
            \addlegendentry{\(x^{2} + y^{2} = 9\)}
            
            \path[name path = C] (0,0) -- (0,0);
            
            \addplot[only marks,black] coordinates {(0,3) (0,-3)};
            
            \addplot[blue!70,opacity=0.4,even odd rule] fill between  [of=B and C];
        \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

像这样(根据需要更改颜色并在您喜欢的地方添加方程式):

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \filldraw[red!50] (-5.3,-5.3) rectangle (5.3,5.3);
        %\filldraw[green!3](-5.2,-5.2) rectangle (5.4,5.4);
        \filldraw[white] (0,0) ellipse (5 and 3);
        \filldraw[red!50] (0,0) circle(3);
        \draw[cyan,-latex] (-5.2,0)--(5.4,0) node[right] () {$x$};
        \foreach \x in {-5,-4,...,5}
            \draw (\x,.1)--(\x,-.1) node[below] () {$\x$};
        \draw[cyan,-latex] (0,-5.2)--(0,5.4) node[above] () {$y$};
        \foreach \y in {-5,-4,...,5}
        \draw (.1,\y)--(-.1,\y)  node[left] () {$\y$};
    \end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

相关内容