3

Tikz newbie here. How can I draw something like below in tikz. The angles/radius of each sector are fixed but the locations may change. Text/grid are not needed. Radial bar chart

Here is what I have so far

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

\begin{document}

\begin{tikzpicture} \draw circle (1cm); \filldraw[fill=blue!40] (320:1cm) -- (0,0) -- (220:1cm) arc[start angle=220, end angle=320, radius=1cm] -- cycle; \filldraw[fill=blue!40] (0:1cm) -- (0,0) -- (-60:1cm) arc[start angle=0, end angle=-60, radius=1cm] -- cycle; \end{tikzpicture}

\end{document}

I get this enter image description here

4 Answers4

9

Here is an automated version. Define a new command \sectorfill that takes a comma-separated list for input, where each entry has the form <percentage>/<color>. For example,

\sectorfill{25/blue,50/red,75/green,60/orange}

would create 4 sectors with radii given as percentages and respective colors. Any color that TikZ understands will work (for example, green!40!black).

The command:

\sectorfill{25/blue,50/red,75/green,60/orange,17/yellow,92/purple,47/brown,81/black,53/green!40!black}

creates the following image: enter image description here

Here is the code:

\documentclass{article}

\usepackage{tikz}

\newcounter{nsect} \newcommand{\sectorfill}[1]{\setcounter{nsect}{0}\begin{tikzpicture}[scale=.5, gray] \foreach \i in {1,...,10}{\draw (0,0) circle[radius=\i];} \foreach [var=\r, var=\c] in {#1}{\addtocounter{nsect}{1}} \foreach [var=\r, var=\c, count=\n, evaluate=\n as \t using 360/\value{nsect}] in {#1}{ \draw(0,0)--(\n\t:10); \drawfill=\c, opacity=.7--(\n\t:\r/10) arc(\n\t:(\n-1)\t:\r/10)--cycle; } \end{tikzpicture}}

\begin{document}

\sectorfill{25/blue,50/red,75/green,60/orange,17/yellow,92/purple,47/brown,81/black,53/green!40!black}

\end{document}

Sandy G
  • 42,558
4

Here a suggestion or more like a proof of concept of how to draw this in tikz. with \foreach to draw the basic structure and \filldraw for colorization.

\documentclass[border=3.14mm]{standalone}

\usepackage{tikz} \usetikzlibrary{backgrounds}

\begin{document} \begin{tikzpicture}

%filling the cake
\filldraw[opacity=0.5,fill=gray!10!white, draw=gray!10!white](0,0) -- (10mm,0mm) arc (0:360:10mm) -- cycle;
\filldraw[fill=white, draw=white](0,0) -- (0.1mm,0mm) arc (0:360:0.1mm) -- cycle;

\filldraw[opacity=0.5,fill=green!20!white, draw=none](0,0) -- (7mm,0mm) arc (0:45:7mm) -- cycle;    
\filldraw[opacity=0.5,fill=red!20!white, draw=none](0,0) -- (6mm,0mm) arc (0:-45:6mm) -- cycle;

\filldraw[opacity=0.5,fill=blue!20!white, draw=none](0,0) -- (-3mm,0mm) arc (0:-45:-3mm) -- cycle;
\filldraw[opacity=0.5,fill=yellow!20!white, draw=none](0,0) -- (-8mm,0mm) arc (0:45:-8mm) -- cycle;

\filldraw[opacity=0.5,fill=orange!20!white, draw=none] (0,0) -- (0,0.5) arc (90:45:0.5cm);
\filldraw[opacity=0.5,fill=brown!20!white, draw=none] (0,0) -- (0,-0.5) arc (-90:-45:0.5cm);

\filldraw[opacity=0.5,fill=black!20!white, draw=none] (0,0) -- (0,0.9) arc (90:135:0.9cm);
\filldraw[opacity=0.5,fill=magenta!20!white, draw=none] (0,0) -- (0,-0.5) arc (-90:-135:0.5cm);



%grid
%rings
\foreach \x in {0.2,0.4,0.6,0.8,1}
\draw[line width=0.05mm,draw=white] (0,0) circle (\x cm);
%lines
\foreach \y in {0,45,90,135,180,225,270,315,360}    
\draw[line width=0.05mm,draw=white] (0,0) -- (\y:1cm);
\end{tikzpicture}

\end{document}

enter image description here

Whithout grid:

enter image description here

Roland
  • 6,655
1

The wheelchart package, which I wrote, can be used.

The data are first stored in the macro \WClist. Here, the first value corresponds to the size and the second value to the color.

The gap between the slices is obtained with the key gap.

There are 2 wheelcharts. The first one draws the slices. Here the key value=1 is used so that the angle of each slice is the same. The outer radius is given by the first variables in \WClist.

In the second wheelchart, the key wheel data=Element \WCcount is used. The macro \WCcount gives the current number of the slice. The rotation depends on the angle given by \WCmidangle. This is set in the key wheel data style.

enter image description here

\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\sffamily
\def\WClist{%
  9/blue!50!black,
  6/blue,
  7/cyan,
  8/green,
  4/green!60!black,
  8/green!30!black,
  9/orange,
  7/orange!50!black,
  7/red,
  8/red!50!black%
}
\fill[gray!10] (0,0) circle[radius=11];
\wheelchart[
  data=,
  gap,
  radius={0}{\WCvarA},
  value=1
]{\WClist}
\wheelchart[
  data=,
  radius={10}{11},
  slices style={fill=none},
  value=1,
  wheel data=Element \WCcount,
  wheel data pos=0.5,
  wheel data style={
    darkgray,
    rotate={\WCmidangle<=180?\WCmidangle-90:\WCmidangle+90}
  }
]{\WClist}
\foreach\n in {1,...,11}{
  \draw[gray] (0,0) circle[radius=\n];
}
\foreach\n in {1,...,5}{
  \draw[gray] ({18+36*\n}:-11)--({18+36*\n}:11);
}
\end{tikzpicture}
\end{document}
matexmatics
  • 4,819
0

Here is my answer. If you can come up with something clever, do share.

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

\begin{document}

\begin{tikzpicture} \draw circle (2cm); \filldraw[fill=red!40] (90:0.5cm) -- (0,0) -- (0:0.5cm) arc[start angle=0, end angle=90, radius=0.5cm] -- cycle; \filldraw[fill=green!40] (180:0.75cm) -- (0,0) -- (90:0.75cm) arc[start angle=90, end angle=180, radius=0.75cm] -- cycle; \filldraw[fill=blue!40] (270:1cm) -- (0,0) -- (180:1cm) arc[start angle=180, end angle=270, radius=1cm] -- cycle; \filldraw[fill=yellow!40] (360:1.5cm) -- (0,0) -- (270:1.5cm) arc[start angle=270, end angle=360, radius=1.5cm] -- cycle;

\end{tikzpicture}

\end{document}

enter image description here