from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
plt.figure(figsize = (15,10),dpi = 80)
x = [1,2,3,4,5,6,7]
y = [17, 17, 18, 15, 11, 11, 13]
plt.plot(x,y)
x_label = ('星期{}'.format(i) for i in x)
y_label = ('{}℃'.format(i) for i in y)
plt.xticks(x,x_label)
plt.yticks(y,y_label)
print(x_label)
plt.show()
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6c74a8ff7e076df27e44cb1044469a07.png)
import random
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
x = range(120)
y_shanghai = [random.uniform(15, 18) for i in x]
y_shenzhen = [random.uniform(20, 25) for i in x]
plt.figure(figsize=(15, 10), dpi=100)
plt.plot(x, y_shanghai, color='y', label='上海', linestyle='-.')
plt.plot(x, y_shenzhen, color='g', label='深圳', linestyle='-')
plt.legend()
x_label = ["11点{}分".format(i) for i in range(60)]
x_label += ["12点{}分".format(i) for i in range(60)]
y_label = ["{}℃".format(i) for i in range(40)]
plt.xticks(x[::5], x_label[::5],rotation = 45)
plt.yticks(range(40)[::5], y_label[::5])
plt.grid(True, linestyle='--', alpha=0.6)
plt.xlabel("时间")
plt.ylabel("温度")
plt.title("城市上午11-12点气温变化")
plt.savefig('test1.png')
plt.show()
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6431c32d994e225ba648f3db1d2250ed.png)