创建环形图

创建环形图

我见过甜甜圈图,但它看起来不像一个环,而是环的各个部分是不相交的。

2D 版本

3D 版本

如何创建它们?

相关问题: 1.如何使用 pgf-plot 设计 3D 甜甜圈饼图? 2.我怎样才能制作出像 PGF 手册第 88 页那样的“环形(或轮形)图表”? 3.如何画咖啡杯(感谢@PrzemysławScherwentke)4.在 TeX 中创建环形图

对于 2D 部分,我尝试对以下代码进行一些调整,这些代码厚颜无耻地从第四个问题的答案,但没有找到这样的明显的方式:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}

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

% The main macro
\newcommand{\wheelchart}[1]{
    % Calculate total
    \pgfmathsetmacro{\totalnum}{0}
    \foreach \value/\colour/\name in {#1} {
        \pgfmathparse{\value+\totalnum}
        \global\let\totalnum=\pgfmathresult
    }

    \begin{tikzpicture}

      % Calculate the thickness and the middle line of the wheel
      \pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius}
      \pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2}

      % 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 in {#1} {
            \pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360}

            % Calculate the percent value
            \pgfmathsetmacro{\percentage}{\value/\totalnum*100}
            % 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<180?"west":"east")
            } \edef\textanchor{\pgfmathresult}
            \pgfmathsetmacro\labelshiftdir{1-1*(-\midangle>180)}

            % Draw the color segments. Somehow, the \midrow units got lost, so we add 'pt' at the end. Not nice...
            \fill[\colour] (-\cumnum:\outerradius) arc (-\cumnum:-(\newcumnum):\outerradius) --
            (-\newcumnum:\innerradius) arc (-\newcumnum:-(\cumnum):\innerradius) -- cycle;

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

      \end{scope}
    \end{tikzpicture}
}
\wheelchart{26/cyan,  28/orange, 33.5/yellow, 12/blue!50!red}

\end{document}

相关内容