项目 数据可视化6

 1 import csv
 2 
 3 from matplotlib import pyplot as plt
 4 
 5 filename = 'sitka_weather_07-2014.csv'
 6 
 7 with open(filename) as f:
 8     reader = csv.reader(f)
 9     header_row = next(reader)
10     
11 
12     highs =[]
13     for row in reader:
14         high = int(row[1])
15         highs.append(high)
16 
17 
18 fig = plt.figure(dpi=128,figsize=(10,6))
19 plt.plot(highs,c='red')
20 
21 plt.title("Daoly high temperatures,July 2014",fontsize=24)
22 plt.xlabel("",fontsize=16)
23 plt.ylabel("Temperature(F)",fontsize=16)
24 plt.tick_params(axis='both',which='major',labelsize=16)
25 
26 plt.show()

 import csv
from datetime import datetime

from matplotlib import pyplot as plt

filename = 'sitka_weather_07-2014.csv'

with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)
    
    dates,highs=[],[]

    for row in reader:
        current_date = datetime.strptime(row[0], "%Y-%m-%d")
        dates.append(current_date)
        high = int(row[1])
        highs.append(high)


fig = plt.figure(dpi=128,figsize=(10,6))
plt.plot(dates,highs,c='red')

plt.title("Daoly high temperatures,July 2014",fontsize=24)
plt.xlabel("",fontsize=16)
fig.autofmt_xdate()
plt.ylabel("Temperature(F)",fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=16)

plt.show()

 

猜你喜欢

转载自www.cnblogs.com/zhulvbo/p/8964512.html
今日推荐