3

I know I'm asking a lot. But by chance, is there someone who knows a package capable of drawing nested pie chart in Latex ? Something like this :

enter image description here

PS : It's more curiosity than real need, Python does it very well ;)

Stefan Pinnow
  • 29,535
Cla-Jan
  • 121
  • 1
    I don't know any package that could render this very fast, but it's mangable in TikZ, of course, with a bit of effort. I'm pretty sure that this type of question was already asked in the past. – SebGlav Jan 28 '22 at 09:56
  • 1
    If you are doing this in matplotlib, you could use a Latex-friendly backend... https://tex.stackexchange.com/q/508567/15036 – Thruston Jan 28 '22 at 10:32
  • https://tex.stackexchange.com/a/159876/1952 – Ignasi Jan 28 '22 at 11:36
  • Thanks ! Yeah I suppose it's possible to do it with Tikz, but very long ^^ – Cla-Jan Feb 05 '22 at 17:46

1 Answers1

5

The answer below uses the wheelchart package, which I wrote.

A command \WCtest is defined of which the output depends on whether the percentage is larger than 1. This command is used in the keys data and wheel data.

Using the key gap={\WCpercentage>1?0.03:0}, a gap between slices is created if the percentage is larger than 1. Otherwise, no gap is created.

The legend is determined by the key legend. This is a tabular which is placed in a \node. The rows are determined by the key legend row. The result of all rows can be obtained with \WClegend.

A separate \wheelchart is used for each ring.

enter image description here

\documentclass[border=6pt,dvipsnames]{standalone}
\usepackage{wheelchart}
\usepackage{siunitx}
\sisetup{text-family-to-math}
\begin{document}
\begin{tikzpicture}
\sffamily
\def\WCtest#1#2{\pgfmathparse{\WCpercentage>1?"#1":"#2"}\pgfmathresult}
\pgfkeys{
  /wheelchart,
  data=\WCtest{}{\qty{\WCvarA}{\percent}},
  data style=gray,
  gap={\WCpercentage>1?0.03:0},
  gap radius=0.03,
  start angle=0,
  wheel data=\WCtest{\qty{\WCvarA}{\percent}}{},
  wheel data pos=0.5
}
\wheelchart[
  legend row={\tikz\fill[\WCvarB] (0,0) rectangle (0.3,0.3); & \WCvarC},
  legend={
    \node[anchor=east] at (-5,0) {%
      \begin{tabular}{rl}%
      \WClegend%
      \end{tabular}%
    };
  },
  middle=District AAL:\\\textcolor{gray}{Rs $12.9$ L},
  radius={1.5}{3},
  wheel data style=white
]{%
  43.1/Cerulean/Residential Buildings,
  24/Green/Economic Sectors,
  22.1/Red/Critical Buildings,
  10.8/gray/Transportation Infrastructure%
}
\wheelchart[
  radius={3}{4},
  wheel data style=gray
]{%
  20.9/Cerulean!50,
  16.2/Cerulean!30,
  6.02/Cerulean!10,
  9.59/Green!50,
  9.33/Green!30,
  5.11/Green!10,
  16.4/Red!50,
  5.7/Red!30,
  10.6/gray!50,
  0.221/gray!30%
}
\end{tikzpicture}
\end{document}
matexmatics
  • 4,819