使用matplotlib库画一个圆饼图,并且把圆饼图的文字注释部分在右上角标识出来。
时间: 2023-05-19 07:07:13 浏览: 116
好的,以下是使用matplotlib库画一个圆饼图的代码:
```python
import matplotlib.pyplot as plt
# 数据
labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]
# 颜色
colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99']
# 画图
fig1, ax1 = plt.subplots()
ax1.pie(sizes, colors=colors, labels=labels, autopct='%1.1f%%', startangle=90)
# 标题
ax1.set_title('Pie Chart')
# 注释
ax1.legend(loc='upper right')
# 显示图形
plt.show()
```
这段代码可以画出一个圆饼图,并且在右上角标识出了圆饼图的文字注释部分。
阅读全文
相关推荐









