|  | 
 
 
 楼主|
发表于 2019-11-20 11:15:14
|
显示全部楼层 
| 谢谢!
 我刚刚试了try except语句,
 except ValueError:
 print(date,'missing data')
 
 但是运行以后并没有打印这行字?是为什么。。
 import  csv
 from matplotlib import pyplot as plt
 from datetime import datetime
 
 filename = 'death_valley_2018_simple.csv'
 with open(filename) as f:
 reader = csv.reader(f)
 header_row = next(reader)
 
 dates,tmax,tmin=[],[],[]
 for row in reader:
 try:
 high=int(row[4])
 low=int(row[5])
 date=datetime.strptime(row[2],'%Y/%m/%d')
 except ValueError:
 print(date,'missing data')
 else:
 dates.append(date)
 tmax.append(high)
 tmin.append(low)
 
 fig = plt.figure()
 plt.plot(dates,tmax,c='red')
 plt.plot(dates,tmin,c='blue')
 plt.fill_between(dates,tmax,tmin,facecolor='yellow',alpha=0.5)
 
 plt.title('temperature',fontsize=25)
 plt.xlabel('date',fontsize=20)
 fig.autofmt_xdate()
 plt.ylabel('temperature',fontsize=10)
 plt.tick_params(axis='both',which='major',fontsize=14)
 
 plt.show()
 还出现了一个问题,ValueError: keyword fontsize is not recognized,这个怎么解决
 | 
 |