0

I'm trying to get an easy to read graph, but when I plot it with matplotlib.pyplot, the y-axis doesn't read consistently like how the x-axis is (the y-axis goes from 26 to 25 to 24 to 37, etc) What am I doing wrong!

matplotlib output

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()

My results are graphed correctly but are poorly graphed in terms of being constant

azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

0

Your data is read as string you need to convert to int (or float) by yourself

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
azro
  • 53,056
  • 7
  • 34
  • 70