import os
import numpy as np
import csv
import matplotlib.pyplot as plt
import matplotlib
path = 'D:/Dhy/毕设/2014北京数据/beijing2014空气质量/beijing_20140101-20141231'
name = os.listdir(path)
print(name)
pm25_24h = []
date = []
for i in range(0, 31):
    rows = []
    with open(path+'/'+name[i], 'r', errors='ignore')as f:
        f_csv = csv.reader(f)
        for row in f_csv:
            rows.append(row)
    if rows[117][7] != '':
        pm25_24h.append(float(rows[117][7]))
    else:
        pm25_24h.append(None)
    date.append(rows[117][0])
dates = []
for i in range(len(date)):
    dates.append(date[i][6:8])
x = list(range(0, len(pm25_24h)))
print(pm25_24h)
#pm25_24h = list(map(int, pm25_24h))
fig = plt.figure(figsize=(6, 5.5))
ax = plt.subplot()
varname = 'PM25_24h'
ax.plot(x, pm25_24h, '-o', linewidth=2.0)
#ax.plot(x, np.ones(len(date))*100, '-', linewidth=2.0)
date=date
plt.xticks(x[0::2], dates[0::2], fontsize=15, rotation=45)
plt.xlim(0, 30)
plt.ylim(0, 500)
plt.xlabel('January', fontsize=18)
plt.yticks(fontsize=15)
plt.ylabel('PM$_{2.5}$'+' μg/m$^{3}$', fontsize=18)
#plt.title(varname, fontsize=20)
fig = plt.gcf()  # 获取当前窗口
fig.subplots_adjust(top=0.98, bottom=0.13, left=0.15, right=0.96,)  # 设置窗口左内边距

#plt.savefig(varname + '.png')
plt.show()