我正在使用pgfplots
和绘制方程式r=1
和r=1-sin(\x/2)
,但我想对曲线形成的 3 个不同区域进行着色。我找到了一个指向此错误报告的链接,该链接询问有关fill between
在环境中使用的信息polaraxis
,该链接指向另外 2 个 TeX.SX 帖子:https://github.com/pgf-tikz/pgfplots/issues/124
这篇文章遮蔽了包含原点的区域:pgfplots 中两个极坐标方程的图形之间的阴影
这篇文章使用的axis
环境而不是polaraxis
环境:遮蔽两条极坐标曲线之间的区域
以下是我正在使用的代码:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{polar, fillbetween}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{polaraxis}
[
domain=0:360,
samples=180,
grid=both,
grid style={line width=0.1pt, draw=gray!75},
major grid style={black},
minor x tick num=3,
minor y tick num=3,
xmin=0, xmax=360,
ymin=0, ymax=2.25,
xtick={0,45,...,360},
xticklabels={},
ytick={3},
yticklabel style={anchor=north},
]
\addplot[draw=red, domain=0:720] {1-sin(\x/2)};
\addplot[draw=blue, domain=0:360] {1};
\end{polaraxis}
\end{tikzpicture}
\end{document}
答案1
这是一种不太复杂但有效的方法。
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar, fillbetween}
\pgfplotsset{compat=newest}
\makeatletter
\tikzset{reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}}}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=1]
\pgfplotsset{set layers}
\begin{polaraxis}
[axis on top,
domain=0:360,
samples=180,
grid=both,
grid style={line width=0.1pt, draw=gray!75},
major grid style={black},
minor x tick num=3,
minor y tick num=3,
xmin=0, xmax=360,
ymin=0, ymax=2.25,
xtick={0,45,...,360},
xticklabels={},
ytick={3},
yticklabel style={anchor=north},
]
\addplot[draw=red, domain=0:720,save path=\RedPath] {1-sin(\x/2)};
\addplot[draw=blue, domain=0:360,save path=\BluePath] {1};
\pgfonlayer{axis background}
\fill[blue!20,reuse path=\BluePath];
\fill[red!20,even odd rule,reuse path=\RedPath];
\clip[reuse path=\BluePath];
\fill[cyan!20,even odd rule,reuse path=\RedPath];
\endpgfonlayer
\end{polaraxis}
\end{tikzpicture}
\end{document}