使用 pgf-pie chart 很容易

使用 pgf-pie chart 很容易

我想绘制以下饼图,其中的分区以角度表示,而不是百分比。请帮忙

在此处输入图片描述

答案1

我刚刚做了一些改变杰克的精彩回答我怎样才能制作出像 PGF 手册第 88 页那样的“环形(或轮形)图表”?结果是:

在此处输入图片描述

修改后的代码为:

\documentclass[tikz,border=2mm]{standalone}
\usepackage{siunitx}
\begin{document}

% Adjusts the size of the wheel:
\def\outerradius{2.2cm}

% The main macro
\newcommand{\piechart}[1]{
    \begin{tikzpicture}
      % Rotate so we start from the top
      \begin{scope}[rotate=90]

      % Loop through each value set. \cumnum keeps track of where we are in the wheel
      \pgfmathsetmacro{\cumnum}{0}
      \foreach \value/\colour/\name in {#1} {
            \pgfmathsetmacro{\newcumnum}{\cumnum + \value}

            % Calculate the mid angle of the colour segments to place the labels
            \pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2}

            % This is necessary for the labels to align nicely
            \pgfmathparse{
               (-\midangle<5?"south":
                (-\midangle<85?"south west":
                 (-\midangle<105?"west":
                  (-\midangle<175?"north west":
                   (-\midangle<185?"north":
                    (-\midangle<265?"north east":
                     (-\midangle<275?"east":
                      (-\midangle<355?"south east":"south")
                     )
                    )
                   )
                  )
                 )
                )
               )
            } \edef\textanchor{\pgfmathresult}

            % Draw the color segments. Somehow, the \midrow units got lost, so we add 'pt' at the end. Not nice...
            \fill[\colour] (0,0) -- (-\cumnum:\outerradius) arc (-\cumnum:-\newcumnum:\outerradius)--cycle;
            % Draw the data labels
            \node at (\midangle:\outerradius + 1ex) [inner sep=0pt, outer sep=0pt, ,anchor=\textanchor]{\name: \ang{\value}};

            % Set the old cumulated angle to the new value
            \global\let\cumnum=\newcumnum
        }

      \end{scope}
      \draw[gray] (0,0) circle (\outerradius);
    \end{tikzpicture}
}

% Usage: \piechart{<value1>/<colour1>/<label1>, ...}
\piechart{79.2/green/A,  21.6/yellow/B, 64.8/red/C, 122.4/blue/D, 14.4/pink/E, 57.6/white/F}

\end{document}

更新:使用wheelchart

可以使用 Matthias Floré 的wheelchart包裹。

\documentclass[tikz, border=2mm]{standalone}
\usepackage{wheelchart}
\usepackage{siunitx}

\begin{document}

\begin{tikzpicture}
\wheelchart[
pie,
contour=gray,
data={\WCvarC: \ang{\WCvarA}},
]{%
79.2/green/A,
21.6/yellow/B,
64.8/red/C,
122.4/blue/D,
14.4/pink/E,
57.6/white/F%
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

使用 pgf-pie chart 很容易

在此处输入图片描述

\documentclass{article}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}
  \pie[text=inside,sum=auto,radius=4,after number=\ensuremath{^\circ},
  color=white,rotate=10]{
      79.2/A,
      21.6/F,
      64.8/E,
      122.4/D,
      14.4/C,
      57.6/B
  }
\end{tikzpicture}
\end{document}

相关内容