2

I like the pie chart from http://www.texample.net/tikz/examples/pie-chart/, but it's in grey color.

Then I found the modified version to add colors by "Sigur" here:How to give different color to each pie?

but still, I need to specify the color by name.

Is there anyway to incorporate colormap as here (by Ronny):How to use colors from a pgfplots colormap in own draw

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\pgfplotsset{compat=1.12}
\tikzset{ellC/.style={/utils/exec={\pgfplotscolormapdefinemappedcolor{#1}},%
    draw=mapped color!80!black, fill=mapped color!80!white}}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[hide axis,
            colormap/hsv,
            xmin=-2.5, xmax=2.5,
            ymin=-.5, ymax=.5,
            axis equal]
        \draw[ellC=0, rotate around={-20:(0,0)}] (0,0) ellipse (.5 and .25);
        \draw[ellC=50, rotate around={0:(1,0)}] (1,0) ellipse (.45 and .3);
        \draw[ellC=100, rotate around={20:(2,0)}] (2,0) ellipse (.4 and **strong text**.35);
    \end{axis}
    \end{tikzpicture}
\end{document}

into those pie chart example.

  • I think stefan's answer solves your problem – percusse May 30 '16 at 7:24
3

Adapting Stefan's code to Sigur's answer, a possible solution could be

\documentclass{article}

\usepackage{calc}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}

\tikzset{
    mycolor/.style={
        color of colormap={#1},
        fill=.!30,
    }
}

\begin{document}
\newcommand{\slice}[5]{ %% use 5 arguments here
  \pgfmathparse{0.5*#1+0.5*#2}
  \let\midangle\pgfmathresult

  % slice %% I changed !10 to !30 to get darker color
  % use the fifth argument #5 to pass the color  
  \draw[thick, mycolor={#5}] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;

  % outer label
  \node[label=\midangle:#4] at (\midangle:1) {};

  % inner label
  \pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
  \let\temp\pgfmathresult
  \pgfmathparse{max(\temp,-0.5) + 0.8}
  \let\innerpos\pgfmathresult
  \node at (\midangle:\innerpos) {#3};
}

\begin{tikzpicture}[scale=3]

\newcounter{a}
\newcounter{b}
%% -------------- use the new variable \c to pass the color
\foreach \p/\t [evaluate=\p as \color using \p*25] in {20/type A, 4/type B, 11/type C, 49/type D, 16/other}
  {
    \setcounter{a}{\value{b}}
    \addtocounter{b}{\p}
    \slice{\thea/100*360}
          {\theb/100*360}
          {\p\%}{\t}{\color}  %% here we use the fifth variable
  }

\end{tikzpicture}

\end{document}

The color used in this case is comuputed with \p*25 where \p corresponds to the pie section. You'll have to decide which mapping to use.

enter image description here

1

The same with PSTricks. Run the example with xelatex or pdflatex --shell-escape <file>

\documentclass{article}
\usepackage{auto-pst-pdf,pstricks-add}
\begin{document}

\psframebox*[fillcolor=yellow!80!black!10]{%
\begin{pspicture}(-4,-4)(4,4)
\psChart[userColor={red!30,green!30,
    blue!40,cyan!40,magenta!60}]{ 20, 4, 11, 49, 16 }{1}{2.75}
\pgfforeach \iA/\iB/\iC in {1/20/A,2/4/B,3/11/C,4/49/D,5/16/E}{%
     \rput(psChartI\iA){\small\iB\%}%
     \ncline[nodesepA=0.4,nodesepB=0.75]{psChartI\iA}{psChartO\iA}%
     \ncput[npos=1.2]{\small\iC}}
\end{pspicture}}

\end{document}

enter image description here

\psChart[options]{data}{list of marked elements}{radius}

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.