#如果列表a表示10点到12点的每一分钟的气温,绘制折线图观察每分钟气温的变化情况:a=[random.randint(20,35) for i in range(120)]
import matplotlib.pyplot as plt
import random
from matplotlib import font_manager
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
'''plt.rcParams['font.sans-serif'] = ['FangSong'] # 替换sans-serif字体
plt.rcParams['axes.unicode_minus'] = False #解决坐标轴负数的负号显示问题'''"https://www.jb51.net/article/134546.htm"
x = range(120)
y = [random.randint(20,35)for i in range(120)]
plt.figure(figsize=(20,8),dpi = 80)
plt.plot(x,y)
# 调整x轴的刻度
_xtick_labels =["10点{}分".format(i) for i in range(60)]
_xtick_labels +=["11点{}分".format(i) for i in range(60)]#字符串连接
# 取步长,数字和字符串一一对应,数据的长度一样
plt.xticks(list(x)[::3],_xtick_labels[::3],rotation = 45,fontproperties=font)#坐标轴刻度与坐标轴标签显示一一对应,并旋转45,垂直显示。','
#添加坐标轴描述信息
plt.xlabel('时间',fontproperties=font)
plt.ylabel('温度(℃)',fontproperties=font)
plt.title('10点到12点每分钟的气温变化情况图',fontproperties=font)
plt.savefig('10点到12点每分钟的气温变化情况图')
plt.show()