matplotlib 如何在Python中画一个圆在另一个圆里面,并用各种颜色给线段着色?

k4emjkb1  于 2022-11-24  发布在  Python
关注(0)|答案(1)|浏览(145)

我想绘制多个圆,一个在另一个里面,将它们的边界分成N个相等的部分,并使用特定的颜色为每个圆的每个部分着色,如下图所示:circle(不幸的是,这里只显示了一个圆。我想用这种方式画多个圆,一个在另一个里面。)
如何在Python中执行此操作?

pkln4tw6

pkln4tw61#

您要查找的单词是Nested pie charts。您可以从matplotlib中尝试类似this的单词。

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()

相关问题