'Pie radar chart in python (pizza slices)
I would like to generate a pie radar / spider chart in python with 14 separate categories or "pizza slices". Something similar to this example created in excel or this example created with ggplot2.
This plt example was useful (code below), however the observations for different categories are connected with lines rather than having their own separate sections ("pizza slices"). Any ideas how to do this is python?
import matplotlib.pyplot as plt
import pandas as pd
from math import pi
df = pd.DataFrame({
'group': ['A','B'],
'r1': [2, 23],
'r2': [5, 5],
'r3': [1, 9],
'r4': [1, 1],
'r5': [3, 6],
'r6': [0, 0],
'r7': [17, 53],
'r8': [29, 44],
'r9': [0,2],
'r10': [0, 2],
'r11': [0, 3],
'r12': [1, 2],
'r13': [0, 3],
'r14': [0, 0],
})
categories=list(df)[1:]
N = len(categories)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]
fig = plt.figure(figsize=(6,6))
ax = plt.subplot(111, polar=True)
ax.set_theta_offset(pi / 2)
ax.set_theta_direction(-1)
plt.xticks(angles[:-1], categories)#, rotation=70)
# Draw ylabels
ax.set_rlabel_position(10)
plt.yticks([20,40,60,80,100], ["20","40","60","80","100"], color="black", size=8)
plt.ylim(0,100)
values=df.loc[0].drop('group').values.flatten().tolist()
values += values[:1]
ax.plot(angles, values, linewidth=1, linestyle='solid', label="A")
ax.fill(angles, values, 'b', alpha=0.7)
values=df.loc[1].drop('group').values.flatten().tolist()
values += values[:1]
ax.plot(angles, values, linewidth=1, linestyle='solid', label="B")
ax.fill(angles, values, 'r', alpha=0.1)
plt.legend(loc='upper right', bbox_to_anchor=(0, 0))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

