使用 Tikz 对圆形区域进行阴影处理

使用 Tikz 对圆形区域进行阴影处理

我正在尝试对切成三块的​​圆的区域进行着色。以下是代码。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{tkz-euclide}
\usetikzlibrary{arrows,shadows,positioning, calc, decorations.markings, 
hobby, quotes,angles,decorations.pathreplacing,intersections}
\usepgfplotslibrary{polar}
\usepgflibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{figure}[ht]

\centering

\begin{tikzpicture}[scale=1.25,line width=1pt]
\begin{axis}[
color= white,
xmin=-15, 
xmax=15, 
ymin=-15, 
ymax=15, 
axis equal image, 
axis lines=middle, 
xticklabels={}, 
yticklabels={},
font=\scriptsize,
ticks=none,
xlabel = {},
ylabel = {},
inner axis line style={stealth-stealth}
]

\draw[black, thick, name path=1] (0,0) circle [radius=12];

\addplot[black, domain=-12:12, samples=300, name path = 1] {sqrt(144-x^2)};

\addplot[black, domain=-12:12, samples=300, name path = 2] {-sqrt(144-x^2)};

\draw[white, name path=3] (-12,0) -- (12,0);

\draw[black, dashed] (-3.179,-11.5713) -- (-3.179,11.5713);

\draw[black, dashed] (3.179,-11.5713) -- (3.179,11.5713);

%\addplot[red, fill opacity=0.20] fill between [of=1 and 2,soft clip= 
{domain=-12:-3.179}];


\end{axis}
\end{tikzpicture}

\caption{Slicing the pie into three pieces of equal area.}

\label{pie}

\end{figure}

\end{document}

以下是我将最后一部分注释掉后生成的图像:

在此处输入图片描述

现在,当我取消注释最后一行时,结果就是这样。

在此处输入图片描述

虽然我得到了想要的阴影,但现在图像略微偏离中心,并且已经绘制了轴线,尽管我并不想这样。我应该怎么做才能解决这个问题?

答案1

至于原始问题:fillbetween并不像人们想象的那么“无辜”,它还以填充位于图后面的方式设置图层。(这是我从 Stefan Pinnow 的评论中学到的。)但是,摆脱轴的最简单方法是说hide axis

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{figure}[ht]

\centering

\begin{tikzpicture}[scale=1.25,line width=1pt]
\begin{axis}[hide axis,
xmin=-15, 
xmax=15, 
ymin=-15, 
ymax=15, 
axis equal image, 
font=\scriptsize,
]

\draw[black, thick, name path=1] (0,0) circle [radius=12];

\addplot[black, domain=-12:12, samples=300, name path = 1] {sqrt(144-x^2)};

\addplot[black, domain=-12:12, samples=300, name path = 2] {-sqrt(144-x^2)};


\draw[black, dashed] (-3.179,-11.5713) -- (-3.179,11.5713);

\draw[black, dashed] (3.179,-11.5713) -- (3.179,11.5713);

\addplot[red, fill opacity=0.20] fill between [of=1 and 2,soft clip= 
{domain=-12:-3.179}];
\end{axis}
\end{tikzpicture}
\caption{Slicing the pie into three pieces of equal area.}
\label{pie}
\end{figure}
\end{document}

在此处输入图片描述

但是,如果您不想要轴,为什么不直接用 来画呢tikz?(无论如何,我建议使用极坐标。)

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[clip] (0,0) circle (6);
\fill[red, fill opacity=0.20] (105:6) rectangle (-6,-6);
\draw[dashed] (105:6) -- (-105:6) (75:6) -- (-75:6);
\end{tikzpicture}
\end{document}

在此处输入图片描述

还请注意使用 pgfplots 库fillbetween,参见例如这里(我并不是说这个答案特别有创意,这只是我手头上的一个例子。)

至于你的最后一条评论:这是我的建议

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[thick]
\pgfmathsetmacro{\radius}{4}
\draw[clip] (0,0) circle (\radius);
\fill[red, fill opacity=0.20] (105:\radius) rectangle (-\radius,-\radius);
\fill[blue, fill opacity=0.20] ({-\radius*sin(15)},\radius) rectangle ({\radius*sin(15)},-\radius);
\fill[green, fill opacity=0.20] (75:\radius) rectangle (\radius,-\radius);
\draw[dashed] (105:\radius) -- (-105:\radius) (75:\radius) -- (-75:\radius);
\end{tikzpicture}
\end{document}

这就是我得到的

在此处输入图片描述

相关内容