How to draw circles one inside the other and color the segments with various colors in Python?
Question:
I would like to draw multiple circles, one inside the other, divide their borders in N equal parts, and color each part of every circle with a specific color, like in the following image:
circle
(Unfortunately, here is shown only one circle. I would like to draw multiple circles, one inside the other, in this manner.)
How can I do this in Python?
Answers:
The word you’re looking for is Nested pie charts
. You can try something like this from matplotlib
.
An example is borrowed from here.
import matplotlib.pyplot as plt
# Data to plot
labels = ['Python', 'C++', 'Ruby', 'Java']
sizes = [504, 337, 415, 280]
labels_gender = ['Man','Woman','Man','Woman','Man','Woman','Man','Woman']
sizes_gender = [315,189,125,212,270,145,190,90]
weight_gender = [189,315,270,212,125,145,200,80]
colors = ['#ff6666', '#ffcc99', '#99ff99', '#66b3ff']
colors_gender = ['#c2c2f0','#ffb3e6', '#c2c2f0','#ffb3e6', '#c2c2f0','#ffb3e6', '#c2c2f0','#ffb3e6']
# Plot
plt.pie(sizes, labels=labels, colors=colors, startangle=90,frame=True)
plt.pie(sizes_gender,colors=colors_gender,radius=0.75,startangle=90)
centre_circle = plt.Circle((0,0),0.5,color='black', fc='white',linewidth=0)
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
plt.axis('equal')
plt.tight_layout()
plt.show()
I would like to draw multiple circles, one inside the other, divide their borders in N equal parts, and color each part of every circle with a specific color, like in the following image:
circle
(Unfortunately, here is shown only one circle. I would like to draw multiple circles, one inside the other, in this manner.)
How can I do this in Python?
The word you’re looking for is Nested pie charts
. You can try something like this from matplotlib
.
An example is borrowed from here.
import matplotlib.pyplot as plt
# Data to plot
labels = ['Python', 'C++', 'Ruby', 'Java']
sizes = [504, 337, 415, 280]
labels_gender = ['Man','Woman','Man','Woman','Man','Woman','Man','Woman']
sizes_gender = [315,189,125,212,270,145,190,90]
weight_gender = [189,315,270,212,125,145,200,80]
colors = ['#ff6666', '#ffcc99', '#99ff99', '#66b3ff']
colors_gender = ['#c2c2f0','#ffb3e6', '#c2c2f0','#ffb3e6', '#c2c2f0','#ffb3e6', '#c2c2f0','#ffb3e6']
# Plot
plt.pie(sizes, labels=labels, colors=colors, startangle=90,frame=True)
plt.pie(sizes_gender,colors=colors_gender,radius=0.75,startangle=90)
centre_circle = plt.Circle((0,0),0.5,color='black', fc='white',linewidth=0)
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
plt.axis('equal')
plt.tight_layout()
plt.show()