我正在尝试获得易于阅读的图形,但是当我使用matplotlib.pyplot对其进行绘制时,y轴的读数却不像x轴一样一致(y轴从26变为25到24到37,等等)我在做什么错!
temp = ['26', '26', '25', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24']
hum = ['37', '38', '38', '39', '39', '40', '40', '40', '40', '40', '40', '40', '40', '41', '40', '39', '39', '39', '39', '39', '39', '39', '39']
time = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115]
plt.plot(time, temperature, color="green")
plt.plot(time, humidity, color="orange")
plt.xlabel("time (minutes)")
plt.ylabel("Temp/Humidity (C,%)")
plt.title("Temp and Humidity over time")
plt.show()
我的结果被正确地绘制,但是就常数而言却很难被绘制
您的数据读为string
,您需要自己转换为int
(或浮动)
temp = list(map(int, temp)) # change data from string to int
hum = list(map(int, hum))
plt.plot(time, temp, color="green")
plt.plot(time, hum, color="orange")
plt.axis([None, None, 0, 45]) # if you to set Y limits