Matplotlib 饼图


章节


饼图是另一种常见的图形类型,可以使用pie()方法制作饼图。

示例

# 导入numpy库与matplotlib.pyplot库
import numpy as np
import matplotlib.pyplot as plt

# 准备数据:公司市场占有率
firms = ["Firm A", "Firm B", "Firm C", "Firm D", "Firm E"]
market_share = [20, 25, 15, 10, 20]

# 设置第二项为爆炸(散开)状态
Explode = [0, 0.1, 0, 0, 0]

# 绘制图形
plt.pie(market_share, explode=Explode, labels=firms, shadow=True, startangle=45)
plt.axis('equal')
plt.legend(title="List of Firms")

# 显示
plt.show()

输出

Matplotlib

posted @ 2019-11-14 10:31  吴吃辣  阅读(145)  评论(0编辑  收藏  举报