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



浙ICP备17015664号-1 浙公网安备 33011002012336号 联系我们 网站地图  
@2019 qikegu.com 版权所有,禁止转载