from matplotlib import pyplot as plt
#一天每隔两个小时的气温
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,27,22,18,15]
#设置图片大小
plt.figure(figsize = (10,6),dpi = 80)
#绘图
plt.plot(x,y)
#设置x轴的刻度
_x = [f"{i}h" for i in x]
plt.xticks(list(x),_x,rotation = 45) #rotation -- 旋转的度数
#保存图片
# plt.savefig("保存路径")
#展示图形
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,2*np.pi,100)
y = np.sin(x)
plt.plot(x,y)
# 添加标题和标签
plt.title('正弦函数图')
plt.xlabel('x')
plt.ylabel('y = sin(x)')
plt.xticks([0, np.pi/2, np.pi, 3*np.pi/2, 2*np.pi])
# 添加网格线
plt.grid(True)
plt.show()