答案1
回答你最初的问题,我不知道是否有任何内置方法可以pgf-pie
只使用文本标签而不使用数字,但可以修补负责制作切片的宏来实现这一点:
\documentclass[border=5mm]{standalone}
\usepackage{pgf-pie}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\pgfpie@slice}% this is the macro we're patching
{\scalefont{#3}\shortstack{#4\\\beforenumber#3\afternumber}}% find this
{\scalefont{#3}#4}% and replace with this
{}{}
\makeatother
\begin{document}
\begin{tikzpicture}
\pie[text=inside]{30/$\omega$, 70/$1-\omega$}
\end{tikzpicture}
\end{document}
如果您想使用 Alan 提到的示例中的代码,则需要对其进行修改以使用第三个循环变量来定义颜色。我在代码中指出了我进行修改的位置。
% Original code from http://www.texample.net/tikz/examples/pie-chart/
% by Robert Vollmert
\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand{\slice}[5]{% changed 4 to 5, fifth argument to define colour
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult
% slice
% add #5 after fill=
\draw[thick,fill=#5] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;
% outer label
\node[label=\midangle:#4] at (\midangle:1) {};
% inner label
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
\let\temp\pgfmathresult
\pgfmathparse{max(\temp,-0.5) + 0.8}
\let\innerpos\pgfmathresult
\node at (\midangle:\innerpos) {#3};
}
\begin{tikzpicture}[scale=3]
\newcounter{a}
\newcounter{b}
% add third loop variable for colour
\foreach \p/\t/\clr in {30/$\omega$/blue!20, 70/$1-\omega$/red!30}
{
\setcounter{a}{\value{b}}
\addtocounter{b}{\p}
\slice{\thea/100*360}
{\theb/100*360}
{\t}{}{\clr} % added fifth argument, {\clr}
}
\end{tikzpicture}
\end{document}
最后,对于简单的两部分饼图,这里有一种从头开始制作的方法。
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw[draw=black,fill=blue!30] (0,0) -- (0:2cm) arc[start angle=0,end angle=120,radius=2cm] -- cycle;
\filldraw[draw=black,fill=red!30] (0,0) -- (120:2cm) arc[start angle=120,end angle=360,radius=2cm] -- cycle;
\node at (60:1cm) {$\omega$};
\node at (240:1cm) {$1-\omega$};
\end{tikzpicture}
\end{document}
答案2
现在(v0.7),pgf-pie 有一个hide number
选项似乎可以做到这一点。
\documentclass[border=5mm]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}
\pie[text=inside, hide number]{30/$\omega$, 70/$1-\omega$}
\end{tikzpicture}
\end{document}
答案3
随着最近的 wheelchart
包裹:
\documentclass[tikz,border=2mm]{standalone}
\usepackage{wheelchart}
\begin{document}
\begin{tikzpicture}
\wheelchart[pie, wheel data={\WCvarC}, wheel data pos=0.5, data={}]
{30/{blue!30}/$w$,70/{blue!50}/$1-w$}
\end{tikzpicture}
\end{document}