Pregunta

I've a problem with my Matplotlib graph.

My Programm:
I read sensor data and save it in a csv file with one decimal place (00.0)
after saving I readout the individual data into a list
my list is called tempList and the numbers are float

My Plot:

plt.plot(tempList, color='r', linewidth=2.0)     
plt.xticks(range(len(tempList)), timeList2, size='small', rotation=20) 
plt.axis('auto')
plt.xlabel('Time')
plt.ylabel('degree Celsius')
plt.title('Temperature')
plt.grid(True)
plt.savefig('img/temp.png', format='png', transparent = True)
plt.close()

My result:
http://s24.postimg.org/5ewu74w51/temp.png

My List:
[20.3, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4]

if I make a list with int's everything works, but since I need thoose decimal places I can't use int.
I already tried to set 'ylim' but it doesn't work

EDIT: thanks for the help
I removed the 'plt.axis('auto')'
the solution:

minTemp = math.ceil(min(tempList))
minTemp = round(minTemp, 1)
maxTemp = math.ceil(max(tempList))
maxTemp = round(maxTemp, 1)
plt.ylim((minTemp-1), (maxTemp+1))

plt.ylim((minTemp-1), (maxTemp+1))
¿Fue útil?

Solución

I've made this minimal example. I removed plt.axis('auto') and replaced it with plt.ylim, which seems to work. When I replace plt.ylim by plt.axis('auto'), it doesn't work very well.

from matplotlib import pyplot as plt
import math
tempList = [20.3, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4, 20.4]
plt.plot(tempList)
plt.ylim(math.floor(min(tempList)), math.ceil(max(tempList)))
plt.show()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top