3

You see the following code, which draw you a pie chart

\usepackage{pgf-pie}

\begin{document}
  \begin{tikzpicture}

    \pie[rotate=20, color={white}, sum=auto, after number=, radius=2] {10/, 10/, 10/, 10/, 10/,10/, 10/, 10/}

  \end{tikzpicture}
\end{document}

`

I want the numbers 1 to 8 instead of 10. Is this with the command \pie possible?

  • Do you want the segments to be each 1/8 of total size and just number it from 1 to 8? – moospit Dec 18 '15 at 12:05
  • @moospit yes that's right. When I write the numbers 1 to 8 in the command line. LateX change the size of this pie, The 8 sectors of the circle should be the same size, only the description should be different (from 1 to 8 instead of 10) – danielg Dec 18 '15 at 12:32
4

I am not aware if pgf-pie is supporting this. Otherwise you can use the following code to create your chart. It could also be used in a newcommand or the pic-environment to make it reusable.

You can adjust the parameters mysegments (number of segements) and myradius (radius of segments) for customization.

\documentclass[tikz, border=5mm]{standalone}

\begin{document}    
  \begin{tikzpicture}
    \def\mysegments{8}
    \def\myradius{2}
    \foreach \x in {1,...,\mysegments} {
        \draw (0,0) --++ (360/\mysegments*\x:\myradius) arc (360/\mysegments*\x:360/\mysegments*(\x+1):\myradius);
        \node at (360/\mysegments*\x-180/\mysegments:\myradius/2) {\x};
    }
  \end{tikzpicture}
\end{document}

rendered image

Or with 15 segments (\def\mysemgments{15}): rendered image

2

If you want the segments to be able to have different sizes, you can do it like this:

Code

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

\begin{document}

\newcommand{\Pie}[4][white]%
%[fill color] parts/color, size, rotate
{   \xdef\PieSum{0}
    \foreach \Seg/\Col in {#2}
    {   \pgfmathparse{\PieSum+\Seg}
        \xdef\PieSum{\pgfmathresult}
    }
    \xdef\PieDone{0}
    \begin{scope}[rotate=#4]
        \foreach \Seg/\Col [count=\C] in {#2}
        {   \pgfmathsetmacro{\PieDeg}{\Seg/\PieSum*360}
            \fill[#1, \Col, draw=black] (0,0) -- ++ (\PieDone:#3) arc (\PieDone:\PieDone+\PieDeg:#3) -- cycle;
            \node at  (\PieDone+\PieDeg/2:#3*0.7) {\C};
            \pgfmathparse{\PieDone+\PieDeg}
            \xdef\PieDone{\pgfmathresult}
        }
    \end{scope}
}

\begin{tikzpicture}
 \Pie[orange!50]{5/blue!50,7/,13/,19/green!50,11/}{5}{90}
\end{tikzpicture}

\end{document}

Output

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.