http://etc.usf.edu/clipart/galleries/588-fraction-pies-quarters
我可以画出此链接中的大部分图形。但我想知道的是如何像图 3、4、5、6 中那样对某个区域进行着色。
答案1
我认为这涵盖了所有必需的用例:
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{patterns}
\pgfmathsetbasenumberlength{4}
\tikzset{wedges/.pic={
\pgfmathdectobase\n{#1}{2}\pgfmathtodigitlist{\l}{\n}%
\foreach \p [count=\j from 0] in \l
\path [rotate=-\j*90-90, wedge \p/.try]
(0:0) -- (0:.5) arc (0:90:.5) -- cycle;
}}%
\begin{document}
\begin{tikzpicture}[declare function={xc(\i)=1.5*mod(\i,4);yc(\i)=-1.5*int(\i/4);}]
\foreach \i in {0,...,15}
\path [wedge 0/.style={draw=none}, wedge 1/.style={draw}]
(xc \i, yc \i) pic {wedges=\i};
\foreach \i in {0,...,15}
\path [wedge 0/.style={draw}, wedge 1/.style={draw, shift=(45:1/4)}]
(6.25+xc \i, yc \i) pic {wedges=\i};
\foreach \i in {0,...,15}
\path [wedge 0/.style={draw}, wedge 1/.style={draw, pattern=north west lines}]
(xc \i, -6.25+yc \i) pic {wedges=\i};
\foreach \i in {0,...,15}
\path [wedge 0/.style={fill=black!25}, wedge 1/.style={fill=black!75}]
(6.25+xc \i,-6.25+yc \i) pic {wedges=\i};
\end{tikzpicture}
\end{document}
答案2
PSTricks 解决方案:
\documentclass{article}
\usepackage{pstricks}
% first pie chart
\def\sizeA{2}
% second pie chart
\def\sizeB{1.5}
\def\replacement{0.3}
\pstFPadd\maximum{\sizeB}{\replacement}
\begin{document}
\begin{pspicture}(-\sizeA,-\sizeA)(\sizeA,\sizeA)
\pswedge{\sizeA}{0}{90} % 1st quadrant
\pswedge[fillstyle = hlines]{\sizeA}{90}{180} % 2nd quadrant
\pswedge{\sizeA}{180}{270} % 3rd quadrant
\pswedge[fillstyle = hlines]{\sizeA}{270}{360} % 4th quadrant
\end{pspicture}
\qquad
\begin{pspicture}(-\sizeB,-\sizeB)(\maximum,\maximum)
\rput(\replacement,\replacement){\pswedge{\sizeB}{0}{90}}
\pswedge{\sizeB}{90}{180}
\pswedge{\sizeB}{180}{270}
\pswedge{\sizeB}{270}{360}
\end{pspicture}
\end{document}