python可视化嵌套环形饼图
时间: 2023-10-09 14:06:49 浏览: 187
以下是使用Python和Matplotlib绘制嵌套环形饼图的示例代码:
```python
import matplotlib.pyplot as plt
# 数据
labels = ['A', 'B', 'C', 'D', 'E']
outer_sizes = [30, 20, 15, 10, 25]
inner_sizes = [15, 10, 5, 5, 15]
# 颜色
outer_colors = ['#FFC107', '#2196F3', '#4CAF50', '#E91E63', '#9C27B0']
inner_colors = ['#FFEB3B', '#64B5F6', '#81C784', '#F48FB1', '#BA68C8']
# 绘图
fig, ax = plt.subplots(figsize=(8, 8))
# 外层环形饼图
ax.pie(outer_sizes, labels=labels, colors=outer_colors, startangle=90, radius=1, wedgeprops={'width': 0.4, 'edgecolor': 'white'})
# 内层环形饼图
ax.pie(inner_sizes, colors=inner_colors, startangle=90, radius=0.6, wedgeprops={'width': 0.4, 'edgecolor': 'white'})
# 标题
plt.title('Nested Ring Chart')
# 显示图形
plt.show()
```
结果:
![Nested Ring Chart](https://i.imgur.com/2hKvR84.png)
阅读全文