Python 饼图

1、 示例1

代码

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False

# 生成数据
rng = np.random.RandomState(27)
v = rng.randint(10, 50, 4)

groups = ['第 {} 组' .format(i) for i in range(1, 5)]

# 绘制图形
plt.pie(v, labels=groups, autopct='%1.1f%%')

plt.show()

图形

Python 饼图

 

 

2、对上图进行优化

代码

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False

# 生成数据
rng = np.random.RandomState(27)
v = rng.randint(10, 50, 4)

groups = ['第 {} 组' .format(i) for i in range(1, 5)]
offsets = [0, 0, 0, 0.07]

# 绘制图形
plt.pie(v, labels=groups, explode=offsets, autopct='%1.1f%%', startangle=90, shadow=True)

plt.show()

图形

Python 饼图

 

。。。

上一篇:JAVA使用for循环会重复调用list.size()吗6


下一篇:JAVA使用for循环会重复调用list.size()吗3