1.导入工具包
import matplotlib.pyplot as plt
2.解决中文和符号乱码问题
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
3.参数设置
plt.plot(x,y,c,lw,ls,marker,markersize,markeredgecolor,markerfacecolor,label) 其中,c为颜色,lw为线条宽度,ls设置线条风格:'-'实线、‘-.’点划线、‘--’虚线,marker设置线条上点的形状:‘o’,markersize设置点的大小,markeredgecolor点的边框颜色,markerfacecolor点的填充色,label设置标签
plt.legend(loc)显示图例 loc设置图例显示位置:'upper center'、'best'...
plt.show()
4.画布设置
plt.figure(figsize,dpi,facecolor)figsize设置大小,dpi分辨率,facecolor边框颜色
plt.title()设置标题
plt.xlabel()x轴坐标名称
plt.ylabel()y轴坐标名称
plt.xlim([])确定x轴范围
plt.ylim([])确定y轴范围
plt.xticks([])设置x轴刻度 注:欲使刻度变密集,可调整步长,即传入range(a,b,c)
plt.yticks([])设置y轴刻度 range(min(y),max(y)+1)
5.图形保存
plt.savefig('路径\filename.png/.pdf')
6.简单图形绘制
1)饼图
plt.pie(data,explode,labels,colors,autopct,pctdistance,labeldistance,radius,wedgeprops={'linewidth':1.5,'edgecolor':'green'},textprops={'fontsize':10,'color':