平均能量损失:
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{fadings}
\definecolor{strangegreen}{RGB}{15,111,83}
\tikzset{pics/wedge/.style={code={%
\tikzset{wedge/.cd,#1}
\def\kvw##1{\pgfkeysvalueof{/tikz/wedge/##1}}
\pgfmathtruncatemacro{\itest}{3*(1+sign(sin(\kvw{alpha})))+1+sign(sin(\kvw{beta}))}
\ifcase\itest
%0: alpha>180,beta>180
\draw[fill=\kvw{color},very thin]
(\kvw{alpha}:\kvw{radius})
-- ++(0,-\kvw{h}) arc(\kvw{alpha}:\kvw{beta}:\kvw{radius})
-- ++(0,\kvw{h}) arc(\kvw{beta}:\kvw{alpha}:\kvw{radius});
\or
%1: alpha>180,beta=0,180
\draw[fill=\kvw{color},very thin]
(\kvw{alpha}:\kvw{radius})
-- ++(0,-\kvw{h}) arc(\kvw{alpha}:\kvw{beta}:\kvw{radius})
-- ++(0,\kvw{h}) arc(\kvw{beta}:\kvw{alpha}:\kvw{radius});
\or
%2: alpha>180,beta<180
\draw[fill=\kvw{color},very thin]
(\kvw{alpha}:\kvw{radius})
-- ++(0,-\kvw{h}) arc(\kvw{alpha}:360:\kvw{radius})
-- ++(0,\kvw{h}) arc(360:\kvw{alpha}:\kvw{radius});
\or
%3: alpha=0,180,beta>180
\draw[fill=\kvw{color},very thin]
(180:\kvw{radius})
-- ++(0,-\kvw{h}) arc(180:\kvw{beta}:\kvw{radius})
-- ++(0,\kvw{h}) arc(\kvw{beta}:180:\kvw{radius});
\or
%4: alpha=0,180,beta=0,180
\draw[fill=\kvw{color},very thin]
(180:\kvw{radius})
-- ++(0,-\kvw{h}) arc(180:0:\kvw{radius})
-- ++(0,\kvw{h}) arc(0:180:\kvw{radius});
\or
%5: alpha=0,180,beta=<180
\or
%6: alpha<180,beta=>180
\draw[fill=\kvw{color},very thin]
(180:\kvw{radius})
-- ++(0,-\kvw{h}) arc(180:\kvw{beta}:\kvw{radius})
-- ++(0,\kvw{h}) arc(\kvw{beta}:180:\kvw{radius});
\or
%7: alpha<180,beta=0,180
\pgfmathtruncatemacro{\ibeta}{sign(cos(\kvw{beta}))}
\ifnum\ibeta=1
\draw[fill=\kvw{color},very thin]
(180:\kvw{radius})
-- ++(0,-\kvw{h}) arc(180:360:\kvw{radius})
-- ++(0,\kvw{h}) arc(360:180:\kvw{radius});
\fi
\or
%8: alpha<180,beta<180
\pgfmathtruncatemacro{\ibeta}{sign(sin(\kvw{alpha})-sin(\kvw{beta}))}
\ifnum\ibeta=1
\draw[fill=\kvw{color},very thin]
(180:\kvw{radius})
-- ++(0,-\kvw{h}) arc(180:360:\kvw{radius})
-- ++(0,\kvw{h}) arc(360:180:\kvw{radius});
\fi
\fi
\path[fill=\kvw{color},draw=black] (0,0)--
(\kvw{alpha}:\kvw{radius}) arc(\kvw{alpha}:\kvw{beta}:\kvw{radius})
--cycle;
}},
wedge/.cd,alpha/.initial=0,beta/.initial=0,%beta > alpha!
color/.initial=blue,
mix color/.initial=gray,radius/.initial=3cm,h/.initial=1cm,
/tikz/.cd,
pics/3d pie chart/.style={code={
\def\kvw##1{\pgfkeysvalueof{/tikz/3d pie chart/##1}}
\begin{scope}[yscale=\kvw{aspect},transform shape]
\path[preaction={fill=black,opacity=.8,
path fading=circle with fuzzy edge 20 percent}]
(0,-\kvw{h}-\kvw{radius}/4.5)
circle[radius=1.05*\kvw{radius}];
\pgfmathsetmacro{\mysum}{0}
\foreach \XX/\ZZ in {#1}
{\pgfmathsetmacro{\mysum}{\mysum+\XX}
\xdef\mysum{\mysum}}
\pgfmathsetmacro{\myangle}{\kvw{alpha0}}
\foreach \XX/\ZZ [count=\YY starting from 0,remember=\myangle as \myangle] in {#1}
{\pgfmathsetmacro{\myangleB}{\myangle+\XX*(360/\mysum)}
\pgfmathsetmacro{\mycolor}{{\kvw{colors}}[\YY]}
\pic{wedge={alpha=\myangle,beta=\myangleB,color=\mycolor,
radius/.expanded=\kvw{radius},
h/.expanded=\kvw{h}
}};
\fill (\myangle/2+\myangleB/2:\kvw{radius}*\kvw{eccentricity})
coordinate (\kvw{cname}-\YY) circle[radius=2pt];
\pgfmathtruncatemacro{\mysign}{sign(cos(\myangle/2+\myangleB/2))}
\draw[thick] (\kvw{cname}-\YY) --
++(\myangle/2+\myangleB/2:\kvw{armA}) -- ++
(\mysign*3,0)
\ifnum\mysign<0
node[above right,transform shape=false]{\ZZ}
node[below right,transform shape=false]{\XX\%}
\else
node[above left,transform shape=false]{\ZZ}
node[below left,transform shape=false]{\XX\%}
\fi;
\pgfmathsetmacro{\myangle}{\myangleB}
}
\shade[left color=black,middle color=white,right color=gray,opacity=0.4]
(180:\kvw{radius})
-- ++(0,-\kvw{h}) arc(180:360:\kvw{radius})
-- ++(0,\kvw{h}) arc(360:180:\kvw{radius});
\end{scope}
}},
3d pie chart/.cd,
colors/.initial={"blue","red","orange","green","yellow"},
radius/.initial=3cm,h/.initial=1cm,alpha0/.initial=0,
aspect/.initial=0.6,eccentricity/.initial=0.7,cname/.initial=c,
armA/.initial=2cm,armB/.initial=3cm
}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\path[3d pie chart/.cd,radius=4cm,h=1.5cm,colors={"yellow","strangegreen"}] pic{3d pie chart={36/Nuts,64/Honey}};
\path[xshift=12cm,3d pie chart/.cd,radius=4cm,h=1.5cm,alpha0=45,
colors={"green","yellow","strangegreen"}]
pic{3d pie chart={13/Nuts,5/Honey,82/Beer}};
\end{tikzpicture}
\end{document}
答案1
在 OP 的例子中搜索circle[radius=2pt]
,你会发现
\fill (\myangle/2+\myangleB/2:\kvw{radius}*\kvw{eccentricity})
coordinate (\kvw{cname}-\YY) circle[radius=2pt];
然后只需将其更改为\fill[red] ...;
,点就会用红色填充。