import matplotlib.pyplot as plt import csv
def analyze(): day = range(1, 31) temp = [] datafile = '15_01.csv' with open(datafile, 'rt') as f: data = csv.reader(f, delimiter=',') for d in data: temp.append(d)
print(temp)
x = [day for day, temp, hum in temp]
y = [temp for day, temp, hum in temp]
p = plt.plot(x, y, 'r^--', label='temp')
plt.legend()
plt.title('2015 January tempature')
plt.xlabel('Day'), plt.ylabel('tempature')
plt.show()
if name == 'main': analyze()
The code is the same as above and reads the csv file to draw a temperature graph from the 1st to the 31st
It is not sorted in order as shown above, but is sorted as 1 -> 10 - 19 - > 2 -> 20 - 29 How can I arrange it in the order I want?
python pyplot
I think it's a problem to sort the tempo.
print(temp)
Below
Insert the phrase temp.sort()
and spin the script.
Did you solve it? After a while... I think you might have solved it, but... I had a hard time with a similar problem. To help other people search. I'm leaving it
I think the reason why the axis alignment is weird is that the values in the list are characters. Check it out and convert the values in the list into numbers.
© 2025 OneMinuteCode. All rights reserved.