章节


饼图是另一种常见的图形类型,可以使用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 饼图

相关文章:

  • 2021-06-27
  • 2021-06-20
  • 2022-01-27
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-04
  • 2021-09-25
  • 2021-08-07
  • 2021-04-18
  • 2021-12-26
  • 2021-08-29
  • 2021-10-17
相关资源
相似解决方案