好奇心Log 发表于 2024-4-24 00:25:31

python可视化 | 单站空气质量日历图可视化

在github中经常可以看到下面的日历图,可以用来表示每一天在github上的活跃程度。


类似的方法也可以用到空气质量的可视化方式中来,只要有每天的空气质量指数就可以。

数据
我这里使用的是2020年北京市各个监测站点的空气质量观测数据,原始数据包含PM2.5,PM10,AQI指数,这里选择AQI作为示例。
这里对原始数据做了简单处理,具体过程不赘述,感兴趣的话也可以看文末获取方式。处理后的数据形式如下:

calmap
绘制日历图可以用calmap库直接绘制,安装直接用pip。
详细可视化方法如下:

定义可视化方式
def calendar_heatmap(df, title):
    # 定义颜色
    color_list = ['#009966', '#FFDE33', '#FF9A32', '#CC0033', '#660099']
    levels =

    cmap = colors.ListedColormap(color_list)
    norm = colors.BoundaryNorm(levels, cmap_aqi.N)
   
    # 绘图
    fig, ax = plt.subplots(figsize=(18, 9))

    calmap.yearplot(
      df,            
      vmin=0,
      vmax=300,                  
      cmap=cmap,
      norm=norm,
      how=None,
      year=2020,
    )

    cbar_ax= fig.add_axes()
    cb= mpl.colorbar.ColorbarBase(
      cbar_ax,
      cmap=cmap,
      ticks=levels,            
      norm=norm,
      orientation='vertical',               
      extend='neither',
      extendrect=True,                        
      extendfrac=0.15
    )
   
    # 色标
    cb.set_ticks()
    cb.ax.yaxis.set_tick_params(length=0.01)
    ax.set_ylabel('2020', fontdict=dict(fontsize=25, color='grey'))
   
    # 标题
    ax.set_title(f'AQI of {title}', fontweight = 'bold', fontsize = 25)
    plt.savefig(f'{title}_calendar_heatmap.png')
绘图
cp = df.resample('1d').mean().round(2)['昌平']
calendar_heatmap(cp, 'Changping')
dx = df.resample('1d').mean().round(2)['大兴']
calendar_heatmap(dx, 'DaXing')

最后也对两个测站的空气质量做了个统计

cp_bin = pd.cut(
    cp,
    bins=,
    right=False
).value_counts()

dx_bin = pd.cut(
    dx,
    bins=,
    right=False
).value_counts()

数据&代码获取
1. 代码及测试数据在好奇心Log公众号后台回复calmap。
2. 2013-2020年北京市各监测站空气质量数据在好奇心Log公众号后台回复北京空气质量。
3. 数据处理脚本并不复杂,10行左右,可以自行尝试一下。如果真的有需要,转载本篇文章到朋友圈,截图发至后台。



文章来源于微信公众号:好奇心Log

FrankJScott 发表于 10 小时前

Excellent Cigna Dietitian Blog

For the person asking about wellness coaching programs, virtual nutrition coach, health coach new york city, health and wellness coaching programs, working with a nutritionist to lose weight, working with a nutritionist, dietitian plan, wellness nutrition coach, health coach institute phone number, free fitness and diet plan,I highly recommend this see page about women’s nutritionist near me link or nutrition coach website, international health coach, personalized nutrition coaching, app for healthy diet, working as a health coach, online health coach, holistic nutrition coaching, holistic health coach certification programs, health and wellness coach certification programs, food and nutrition coach, together with this top diabetic dietitian near me forum bearing in mind registered health coach, wellness health coach jobs, difference between nutritionist and nutrition coach, nutritionist recommended diet, holistic health coach, nutrition coaching institute reviews, weight loss dietitians near me, healthy eating coach, health coaching, the health coach, and don't forget this top blue cross blue shield nutritionist site which is also great. Also, have a look at this useful united healthcare nutritionist info which is worth considering with best health diet app, meal plan coach, holistic wellness coach certification, health coach requirements by state, nutrition health coach jobs, be healthy coaching, health coach laws by state, diet for health, wellness coaching prices, health coach programs, together with this her explanation on diabetic dietitian near me link which is worth considering with be healthy coaching, best registered dietitian, difference between nutritionist and nutrition coach, nutrition coaching app, best health diet app,sources tell me about on top of health coaching session, healthy eating and fitness, nutrition coach website, workout and meal plan, health coaching questions for weight loss,for good measure. Check more @ Awesome UG ZEUS Guide b1e2_7b
页: [1]
查看完整版本: python可视化 | 单站空气质量日历图可视化