1

I have a pie chart that displays percentage numbers in a crowded manner, and I want to improve its readability. Is there a way to do that? especially the way the 6.29% and 1.56% appears

enter image description here The code is provided

\documentclass[sn-mathphys,Numbered,iicol]{sn-jnl}
\usepackage{tikz}
\input{Pie}

\begin{document} \begin{figure*} \centering \begin{tikzpicture} [ pie chart, slice type={comet}{blu}, slice type={legno}{rosso}, slice type={coltello}{giallo}, slice type={sedia}{viola}, slice type={caffe}{verde}, slice type={C}{gray}, pie values/.style={font={\small}}, scale=2 ]

\pie[xshift=2.2cm,values of caffe/.style={pos=1.1}]%
    {}{38.57/comet,9.82/legno,37.79/sedia,5.88/C,6.29/caffe,1.56/coltello}



\end{tikzpicture} \caption{xxxx.} \label{tabI} \end{figure*} \end{document}

Inside Pie code

\usepackage{graphicx}%
\definecolor{rosso}{RGB}{220,57,18}
\definecolor{giallo}{RGB}{255,153,0}
\definecolor{blu}{RGB}{102,140,217}
\definecolor{verde}{RGB}{16,150,24}
\definecolor{viola}{RGB}{153,0,153}

\makeatletter

\tikzstyle{chart}=[ legend label/.style={font={\scriptsize},anchor=west,align=left}, legend box/.style={rectangle, draw, minimum size=5pt}, axis/.style={black,semithick,->}, axis label/.style={anchor=east,font={\tiny}}, ]

\tikzstyle{bar chart}=[ chart, bar width/.code={ \pgfmathparse{##1/2} \global\let\bar@w\pgfmathresult }, bar/.style={very thick, draw=white}, bar label/.style={font={\bf\small},anchor=north}, bar value/.style={font={\footnotesize}}, bar width=.75, ]

\tikzstyle{pie chart}=[ chart, slice/.style={line cap=round, line join=round, very thick,draw=white}, pie title/.style={font={\bf}}, slice type/.style 2 args={ ##1/.style={fill=##2}, values of ##1/.style={} } ]

\pgfdeclarelayer{background} \pgfdeclarelayer{foreground} \pgfsetlayers{background,main,foreground}

\newcommand{\pie}[3][]{
    \begin{scope}[#1]
    \pgfmathsetmacro{\curA}{90}
    \pgfmathsetmacro{\r}{1}
    \def\c{(0,0)}
    \node[pie title] at (90:1.3) {#2};
    \foreach \v/\s in{#3}{
        \pgfmathsetmacro{\deltaA}{\v/100*360}
        \pgfmathsetmacro{\nextA}{\curA + \deltaA}
        \pgfmathsetmacro{\midA}{(\curA+\nextA)/2}

        \path[slice,\s] \c
            -- +(\curA:\r)
            arc (\curA:\nextA:\r)
            -- cycle;
        \pgfmathsetmacro{\d}{max((\deltaA * -(.5/50) + 1) , .5)}

        \begin{pgfonlayer}{foreground}
        \path \c -- node[pos=\d,pie values,values of \s]{$\v\%$} +(\midA:\r);
        \end{pgfonlayer}

        \global\let\curA\nextA
    }
    \end{scope}
}

\newcommand{\legend}[2][]{
    \begin{scope}[#1]
    \path
        \foreach \n/\s in {#2}
            {
                  ++(0,-10pt) node[\s,legend box] {} +(5pt,0) node[legend label] {\n}
            }
    ;
    \end{scope}
}

Diana
  • 1,285
  • 7
  • 12

1 Answers1

2

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 7. This command is used in the keys data and wheel data. Here, the percentage is obtained with \WCperc.

The gap is obtained with the key gap.

enter image description here

\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\definecolor{rosso}{RGB}{220,57,18}
\definecolor{giallo}{RGB}{255,153,0}
\definecolor{blu}{RGB}{102,140,217}
\definecolor{verde}{RGB}{16,150,24}
\definecolor{viola}{RGB}{153,0,153}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\def\WCtest#1#2{%
    \pgfmathparse{\WCpercentage>7?"#1":"#2"}%
    \pgfmathresult%
}
\wheelchart[
  counterclockwise,
  data=\WCtest{}{\WCperc},
  gap=0.02,
  perc precision=2,
  radius={0}{2.5},
  wheel data=\WCtest{\WCperc}{}
]{%
  38.59/blu/comet,
  9.84/rosso/legno,
  37.81/viola/sedia,
  5.89/gray/C,
  6.30/verde/caffe,
  1.57/giallo/coltello%
}
\end{tikzpicture}
\end{document}
matexmatics
  • 4,819