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()
图形
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()
图形
。。。
标签:plt,Python,rng,groups,rcParams,np,import 来源: https://www.cnblogs.com/shanger/p/12175564.html