安装matplotlib
绘制条形图和饼图
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
绘制 条形
x = ['商品{}'.format(i) for i in 'ABCDEF']
print(x)
from random import randint
y = [randint(1000, 2000) for i in range(6)]
print(y)
plt.bar(x, y)
plt.show()
饼图
labels = ['员工{}'.format(i) for i in range(1, 7)]
counts = [randint(2000, 15000) for i in range(6)]
print(counts)
# 距离中心点的距离
explode = [0.1, 0, 0, 0, 0, 0]
plt.pie(counts,
explode=explode,
labels = labels,
shadow=True,
autopct = '%1.1f')
plt.show()
折线图
from matplotlib import pyplot as plt
import numpy as pd
import numpy as np
x = [0, 1, 2, 3]
y = [0, 1, 2, 3]
plt.plot(x,y)
plt.show()
散点图
具有横轴和纵轴两个特征
# x = [0, 1, 2, 3]
# y = [0, 1, 2, 3]
# plt.scatter(x,y)
# plt.show()
x = np.random.normal(0,1,10000000)
y = np.random.normal(0,1,10000000)
# alpha透明度 o-1之间,越小越透明
plt.scatter(x,y,alpha=0.1)
plt.show()