线型图:
#导包
import matplotlib.pyplot as plt
#导入字体库
from matplotlib.font_manager import FontProperties#设置本机字体
font = FontProperties(fname='C:/Windows/Fonts/simhei.ttf',size=15)#填充数据
# plt.plot(['2019-03-01','2019-03-02','2019-03-03'],[6,2,4])#绘制方法
# plt.show()#定制数据
x1 = ['2019-03-01','2019-03-02','2019-03-03','2019-03-04','2019-03-05','2019-03-06']
y1 = [0,5,3,2,7,1]x2 = ['2019-03-01','2019-03-02','2019-03-03','2019-03-04','2019-03-05','2019-03-06']
y2 = [18,30,21,15,26,23]#填充数据
plt.plot(x1,y1,label='temperature')
plt.plot(x1,y2,label='water')#设置标题 如果是汉字必须导入字体库不然会识别不出
plt.title('温湿度趋势图',FontProperties=font)
#显示图例
plt.legend()
#绘制
plt.show()
柱状图:
#导包
import matplotlib.pyplot as plt#设置数据
salary = [9000,10000,5000]
group = ['beijing','shanghai','guangzhou']#填充数据
plt.bar(group,salary)#设置标题
plt.title('salary/group')#绘制
plt.show()
散点图:
import matplotlib.pyplot as plt
#导包科学计算库
import numpy as np#设置数据
plt.scatter(2,4)#绘制
# plt.show()#定义x轴数据
x = list(range(0,101))
y = [xvalue * np.random.rand() for xvalue in x]#填充数据
#s 点的大小和粗细
#c 颜色
plt.scatter(x,y,s=20,c='blue')#绘制
plt.show()