散点图和之前的折线图的唯一区别就是绘制时是scatter
方法
语法知识
复习一下语法知识:
- 设置字体:
fm = font_manager.FontProperties(fname="字体包存放路径"
) - 设置x提示语
plt.xlabel("x_label_name",fontproperties=fm)
- 设置y提示语
plt.ylabel("y_label_name",fontproperties=fm)
- 设置标题
plt.title("title_name",fontproperties=fm)
- 设置横坐标
plt.xticks(x_value_list,x_ticks_list,fontproperties=fm,ratation=n)
- 设置纵坐标
plt.yticks(y_value_list,y_ticks_list,fontproperties=fm,rotation=n)
- 绘制散点图
plt.scatter(x,y)
- 显示图片
plt.show()
- 设置画布大小
plt.figure(figsize=(m,n),dpi=p
- 设置图例:
plt.legend(loc="upper right",prop = fm)
- 保存图片:
plt.savefig("savepath+figname")
: # 保存图片至savepath并命名为figname
Demo:绘制March和April温度图
from matplotlib import pyplot as plt from matplotlib import font_manager fm = font_manager.FontProperties(fname='F:\HuaDaBoSi\scratch\practice\img\AlimamaDaoLiTi.ttf') plt.figure(figsize=(20,8),dpi=80) temperature_3 = [12,13,14,28,10,15,17,23,24,24] temperature_4 = [29,23,24,18,20,25,17,16,14,14] x_3 = range(1,31,3) x_4 = range(41,71,3) plt.scatter(x_3,temperature_3,label="March") plt.scatter(x_4,temperature_4,label="April") x_ = list(x_3) + list(x_4) x_tick_label = ["March,{}".format(i) for i in x_3] x_tick_label += ["April,{}".format(i-40) for i in x_4] plt.xticks(x_[::],x_tick_label[::],fontproperties = fm,rotation=45) plt.legend(loc="upper right",prop = fm) plt.xlabel("Time",fontproperties = fm) plt.ylabel("Temperature",fontproperties = fm) plt.title("The temperature between March and April",fontproperties=fm) plt.show()