Tikz/pgfplots 阴影到原点(极地)

Tikz/pgfplots 阴影到原点(极地)

我正在尝试仅对极函数的一个花瓣进行着色。具体来说,我想知道是否有办法对两条射线之间的有界区域进行着色:

在此处输入图片描述

我尝试在其他地方寻找例子,但我见过的大多数例子都涉及在以函数 y=f(x) 下的面积的曲线或阴影。

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    smooth,
    trig format plots=rad,
    axis lines=middle,
    axis equal]
\addplot [domain=0:pi, samples=150, red]
         ({2*sin(5*x)*cos(x)}, {2*sin(5*x)*sin(x)});
\draw [-stealth, ultra thick, dashed, draw=blue] 
        (axis cs: 0,0)
        -- ++(canvas polar cs: radius=3cm,angle=0);
\draw [-stealth, ultra thick, dashed, draw=blue] 
        (axis cs: 0,0)
        -- ++(canvas polar cs: radius=4cm,angle=deg{pi/5});
\end{axis}
\end{tikzpicture}%
\end{document}

任何反馈都将不胜感激!

答案1

因为您知道坐标,所以只需使用fill

\fill[blue,opacity=0.4] (o) -- (a) -- (b);

请注意,我已经命名了坐标。查看完整代码:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    smooth,
    trig format plots=rad,
    axis lines=middle,
    axis equal]
\addplot [domain=0:pi, samples=150, red] ({2*sin(5*x)*cos(x)}, {2*sin(5*x)*sin(x)});
\draw [-stealth, ultra thick, dashed, draw=blue] (axis cs: 0,0)coordinate(o)
        -- ++(canvas polar cs: radius=3cm,angle=0)coordinate(a);
\draw [-stealth, ultra thick, dashed, draw=blue] (o)
    -- ++(canvas polar cs: radius=4cm,angle=deg{pi/5})coordinate(b);
\fill[blue,opacity=0.4] (o) -- (a) -- (b);
%  for filling the petal
% \addplot [domain=0:pi/5, samples=30, red,fill=blue!40] ({2*sin(5*x)*cos(x)}, {2*sin(5*x)*sin(x)}); 
\end{axis}
\end{tikzpicture}%
\end{document}

输出:

在此处输入图片描述

编辑

如果只想为花瓣着色,那么您可以使用来\addplot填充。

\addplot [domain=0:pi/5, samples=30, red,fill=blue!40] ({2*sin(5*x)*cos(x)}, {2*sin(5*x)*sin(x)});

在此处输入图片描述

答案2

您可以只添加您要阴影的图。

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    trig format plots=rad,
    axis lines=middle,
    axis equal]
\addplot[stealth-stealth, ultra thick, dashed, draw=blue,fill=blue!30]  
  coordinates {(2,0) (0,0) ({3*cos(pi/5)},{3*sin(pi/5)})};
\addplot [smooth,domain=0:pi, samples=150, red]
         ({2*sin(5*x)*cos(x)}, {2*sin(5*x)*sin(x)});
\end{axis}
\end{tikzpicture}%
\end{document}

在此处输入图片描述

相关内容