#添加三月份每天的最高气温
a=[11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]from matplotlib import pyplot as plt
from matplotlib import font_manager
y=[11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]
x=range(1,32)#设置大小
plt.figure(figsize=(20,8),dpi=80)#使用scatter绘制散点图
plt.scatter(x, y,label='3月份')#设置字体
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\C:\Windows\Fonts\SIMLI.TTF",size=20)
_xticks_labels=['3月{}日'.format(i)for i in x]#第一个参数表示有那些数,第二个表示刻度上的字
plt.xticks(x[::3],_xticks_labels[::3],fontproperties=my_font,rotation=45)
plt.ylabel('温度',fontproperties=my_font)
plt.xlabel('日期',fontproperties=my_font)
plt.legend(prop=my_font)
plt.show()
2.绘制条形图
a=['流浪地球','疯狂的外星人','飞驰人生','大黄蜂','熊出没','性喜剧之王']#设置height
b=['38.13','19.85','14.89','11.36','6.47','5.93']#进行字体设置
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\C:\Windows\Fonts\SIMLI.TTF",size=10)
plt.figure(figsize=(20,8),dpi=80)
rects=plt.bar(range(len(a)),[float(i)for i in b],width=0.3,color=['r','g','b','r','g','b'])
plt.xticks(range(len(a)),a,fontproperties=my_font)#range(start,end,step)
plt.yticks(range(0,45,5),range(0,41,5))for rect in rects:
height=rect.get_height()
plt.text(rect.get_x()+rect.get_width()/2,height+0.3,str(height),ha="center")
plt.show()
3.绘制横向条形图
a=['流浪地球','疯狂的外星人','飞驰人生','大黄蜂','熊出没','性喜剧之王']#设置height
b=['38.13','19.85','14.89','11.36','6.47','5.93']#进行字体设置
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\C:\Windows\Fonts\SIMLI.TTF",size=10)
plt.figure(figsize=(20,8),dpi=80)
rects=plt.barh(range(len(a)),b,height=0.5,color='r')
plt.yticks(range(len(a)),a,fontproperties=my_font,rotation=45)for rect in rects:
width=rect.get_width()
plt.text(width,rect.get_y()+0.3/2,str(width),va="center")
plt.show()