Python||五城P.M.2.5数据分析与可视化_使用复式柱状图分析各个城市的P.M.2.5月度差异情况(中)

目录

4.上海市空气质量月度差异

5.沈阳市空气质量月度差异


五城P.M.2.5数据分析与可视化_使用复式柱状图分析各个城市的P.M.2.5月度差异情况

4.上海市空气质量月度差异

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt#读入文件
sh = pd.read_csv('./Shanghai.csv')
fig = plt.figure(dpi=100,figsize=(10,5))
def PM(grade,str2,str3):grade_dist = grade.loc[:, [str2, str3]]grade_dist1 = grade_dist.dropna(axis=0, subset=[str3])grade_dist_pm = grade.loc[:, [str3]]grade_dist1_pm = grade_dist_pm.dropna(axis=0, subset=[str3])grade_dist_pm_mean = float(grade_dist1_pm.mean())grade_dist_pm_std = float(grade_dist1_pm.std())pm_area = grade_dist1[np.abs(grade_dist1[str3] - grade_dist_pm_mean) <= 3 * grade_dist_pm_std]grade_dist2 = pm_area.groupby([str2]).mean().reset_index()return grade_dist2def good(pm):#优degree = pm-35for i in range(len(degree)):if degree[i] > 0:degree[i] = 35else:degree[i] += 35return degree
def moderate(pm):#良degree = pm-35for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 40for i in range(len(degree)):if degree[i] > 0:degree[i] = 40else:degree[i] += 40return degree
def lightlyP(pm):#轻度污染degree = pm-75for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 40for i in range(len(degree)):if degree[i] > 0:degree[i] = 40else:degree[i] += 40return degree
def moderatelyP(pm):#中度污染degree = pm - 115for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 35for i in range(len(degree)):if degree[i] > 0:degree[i] = 35else:degree[i] += 35return degree
def heavilyP(pm):#重度污染degree = pm - 150for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 100for i in range(len(degree)):if degree[i] > 0:degree[i] = 100else:degree[i] += 100return degree#上海
#PM_Jingan列
sh_jg = PM(sh,'month','PM_Jingan')
PM_Jingan = np.array(sh_jg['PM_Jingan'])
PM_Jingan_good = good(PM_Jingan)
PM_Jingan_moderate = moderate(PM_Jingan)
PM_Jingan_lightlyP = lightlyP(PM_Jingan)
PM_Jingan_moderatelyP = moderatelyP(PM_Jingan)
PM_Jingan_heavilyP = heavilyP(PM_Jingan)
#PM_Xuhui列
sh_xh = PM(sh,'month','PM_Xuhui')
PM_Xuhui = np.array(sh_xh['PM_Xuhui'])
PM_Xuhui_good = good(PM_Xuhui)
PM_Xuhui_moderate = moderate(PM_Xuhui)
PM_Xuhui_lightlyP = lightlyP(PM_Xuhui)
PM_Xuhui_moderatelyP = moderatelyP(PM_Xuhui)
PM_Xuhui_heavilyP = heavilyP(PM_Xuhui)#导出
width = 0.2
y = [0,0,35,75,115,150]
x1 = list(range(1,len(sh_xh.month)+1))
x2 = [i+width for i in x1]
plt.bar(x1,PM_Jingan_good,width,color='gold')
plt.bar(x1,PM_Jingan_moderate,width,bottom=PM_Jingan_good,color='gold')
plt.bar(x1,PM_Jingan_lightlyP,width,bottom=PM_Jingan_moderate+PM_Jingan_good,color='gold')
p1 = plt.bar(x1,PM_Jingan_moderatelyP,width,bottom=PM_Jingan_lightlyP+PM_Jingan_moderate+PM_Jingan_good,color='gold')
plt.bar(x2,PM_Xuhui_good,width,color='tomato')
plt.bar(x2,PM_Xuhui_moderate,width,bottom=PM_Xuhui_good,color='tomato')
plt.bar(x2,PM_Xuhui_lightlyP,width,bottom=PM_Xuhui_moderate+PM_Xuhui_good,color='tomato')
p2 = plt.bar(x2,PM_Xuhui_moderatelyP,width,bottom=PM_Xuhui_lightlyP+PM_Xuhui_moderate+PM_Xuhui_good,color='tomato')
plt.xticks(sh_xh.month)
plt.title(u"上海市城区空气质量月度差异")
plt.yticks(y,("0","优\n(0~35)","良\n(35~75)","轻度污染\n(75~115)","中度污染\n(115~150)","重度污染\n(150~250)"))
plt.xlabel(u'月份',fontsize=12,verticalalignment='top',horizontalalignment='left', x=1)
plt.ylabel(u'污染程度',rotation='horizontal',fontsize=12,verticalalignment='top',horizontalalignment='left', y=1.1)
plt.legend((p1[0],p2[0]),('Jingan.D','Xuhui.D'))
plt.grid(alpha=0.4)
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.show()

5.沈阳市空气质量月度差异

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt#读入文件
sy = pd.read_csv('./Shenyang.csv')
fig = plt.figure(dpi=100,figsize=(10,5))
def PM(grade,str2,str3):grade_dist = grade.loc[:, [str2, str3]]grade_dist1 = grade_dist.dropna(axis=0, subset=[str3])grade_dist_pm = grade.loc[:, [str3]]grade_dist1_pm = grade_dist_pm.dropna(axis=0, subset=[str3])grade_dist_pm_mean = float(grade_dist1_pm.mean())grade_dist_pm_std = float(grade_dist1_pm.std())pm_area = grade_dist1[np.abs(grade_dist1[str3] - grade_dist_pm_mean) <= 3 * grade_dist_pm_std]grade_dist2 = pm_area.groupby([str2]).mean().reset_index()return grade_dist2def good(pm):#优degree = pm-35for i in range(len(degree)):if degree[i] > 0:degree[i] = 35else:degree[i] += 35return degree
def moderate(pm):#良degree = pm-35for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 40for i in range(len(degree)):if degree[i] > 0:degree[i] = 40else:degree[i] += 40return degree
def lightlyP(pm):#轻度污染degree = pm-75for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 40for i in range(len(degree)):if degree[i] > 0:degree[i] = 40else:degree[i] += 40return degree
def moderatelyP(pm):#中度污染degree = pm - 115for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 35for i in range(len(degree)):if degree[i] > 0:degree[i] = 35else:degree[i] += 35return degree
def heavilyP(pm):#重度污染degree = pm - 150for i in range(len(degree)):if degree[i] < 0:degree[i] = 0degree -= 100for i in range(len(degree)):if degree[i] > 0:degree[i] = 100else:degree[i] += 100return degree#沈阳
#PM_Taiyuanjie列
sy_tyj = PM(sy,'month','PM_Taiyuanjie')
PM_Taiyuanjie = np.array(sy_tyj['PM_Taiyuanjie'])
PM_Taiyuanjie_good = good(PM_Taiyuanjie)
PM_Taiyuanjie_moderate = moderate(PM_Taiyuanjie)
PM_Taiyuanjie_lightlyP = lightlyP(PM_Taiyuanjie)
PM_Taiyuanjie_moderatelyP = moderatelyP(PM_Taiyuanjie)
PM_Taiyuanjie_heavilyP = heavilyP(PM_Taiyuanjie)
#PM_Xiaoheyan列
sy_xhy = PM(sy,'month','PM_Xiaoheyan')
PM_Xiaoheyan = np.array(sy_xhy['PM_Xiaoheyan'])
PM_Xiaoheyan_good = good(PM_Xiaoheyan)
PM_Xiaoheyan_moderate = moderate(PM_Xiaoheyan)
PM_Xiaoheyan_lightlyP = lightlyP(PM_Xiaoheyan)
PM_Xiaoheyan_moderatelyP = moderatelyP(PM_Xiaoheyan)
PM_Xiaoheyan_heavilyP = heavilyP(PM_Xiaoheyan)
#导出
width = 0.2
y = [0,0,35,75,115,150]
x1 = list(range(1,len(sy_tyj.month)+1))
x2 = [i+width for i in x1]
plt.bar(x1,PM_Taiyuanjie_good,width,color='gold')
plt.bar(x1,PM_Taiyuanjie_moderate,width,bottom=PM_Taiyuanjie_good,color='gold')
plt.bar(x1,PM_Taiyuanjie_lightlyP,width,bottom=PM_Taiyuanjie_moderate+PM_Taiyuanjie_good,color='gold')
p1 = plt.bar(x1,PM_Taiyuanjie_moderatelyP,width,bottom=PM_Taiyuanjie_lightlyP+PM_Taiyuanjie_moderate+PM_Taiyuanjie_good,color='gold')
plt.bar(x2,PM_Xiaoheyan_good,width,color='tomato')
plt.bar(x2,PM_Xiaoheyan_moderate,width,bottom=PM_Xiaoheyan_good,color='tomato')
plt.bar(x2,PM_Xiaoheyan_lightlyP,width,bottom=PM_Xiaoheyan_moderate+PM_Xiaoheyan_good,color='tomato')
p2 = plt.bar(x2,PM_Xiaoheyan_moderatelyP,width,bottom=PM_Xiaoheyan_lightlyP+PM_Xiaoheyan_moderate+PM_Xiaoheyan_good,color='tomato')
plt.xticks(sy_tyj.month)
plt.title(u"沈阳市城区空气质量月度差异")
plt.yticks(y,("0","优\n(0~35)","良\n(35~75)","轻度污染\n(75~115)","中度污染\n(115~150)","重度污染\n(150~250)"))
plt.xlabel(u'月份',fontsize=12,verticalalignment='top',horizontalalignment='left', x=1)
plt.ylabel(u'污染程度',rotation='horizontal',fontsize=12,verticalalignment='top',horizontalalignment='left', y=1.1)
plt.legend((p1[0],p2[0]),('Taiyuanjie.D','Xiaoheyan.D'))
plt.grid(alpha=0.4)
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/453195.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

chisel RegInit/UInt/U

val reg RegInit(0.U(8.W)) //ok val reg RegInit(0.UInt(8.W)) //errU 使用在数字 . 后边50.U UInt 使用在IO(new Bundle val a Input(UInt(8.W)) 或者 def counter(max:UInt, a1:UInt) package emptyimport chisel3._ import chisel3.util._class MyCounter extends …

26.云原生ArgoCD高级之ApplicationSet

云原生专栏大纲 文章目录 ApplicationSet介绍ApplicationSet 特性ApplicationSet 安装ApplicationSet 工作原理ApplicationSet 生成器列表类型生成器集群生成器基础使用方法Label Selector 指定集群Values 字段传递额外的参数 git生成器git目录生成参数排除目录git文件生成器矩…

山西电力市场日前价格预测【2024-02-03】

日前价格预测 预测说明&#xff1a; 如上图所示&#xff0c;预测明日&#xff08;2024-02-03&#xff09;山西电力市场全天平均日前电价为442.47元/MWh。其中&#xff0c;最高日前电价为633.60元/MWh&#xff0c;预计出现在09:30。最低日前电价为367.07元/MWh&#xff0c;预计…

计算机设计大赛 深度学习 机器视觉 车位识别车道线检测 - python opencv

0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; 深度学习 机器视觉 车位识别车道线检测 该项目较为新颖&#xff0c;适合作为竞赛课题方向&#xff0c;学长非常推荐&#xff01; &#x1f947;学长这里给一个题目综合评分(每项满分5分) …

Java tomcat 使用spring-task,实现定时任务功能

前言 今天接触到一个需求&#xff0c;需要添加一个定时任务功能&#xff0c;第一反应是启动类EnableScheduling、定时任务方法使用Scheduled实现&#xff0c;导入项目后才发现&#xff0c;这个项目是ssm整合框架的tomcat项目&#xff0c;没有启动类&#xff0c; 于是改变了思路…

机器学习本科课程 实验3 决策树处理分类任务

实验3.1 决策树处理分类任务 使用sklearn.tree.DecisionTreeClassifier完成肿瘤分类&#xff08;breast-cancer&#xff09;计算最大深度为10时&#xff0c;十折交叉验证的精度(accuracy)&#xff0c;查准率(precision)&#xff0c;查全率(recall)&#xff0c;F1值绘制最大深度…

算法学习——华为机考题库8(HJ46 - HJ55)

算法学习——华为机考题库8&#xff08;HJ46 - HJ50&#xff09; HJ46 截取字符串 描述 输入一个字符串和一个整数 k &#xff0c;截取字符串的前k个字符并输出 数据范围&#xff1a; 字符串长度满足 1≤n≤1000 &#xff0c; 1≤k≤n 输入描述&#xff1a; 1.输入待截取的…

Go语言深度解析:探索 crypto/md5 标准库的强大功能

Go语言深度解析&#xff1a;探索 crypto/md5 标准库的强大功能 引言Go语言和MD5的基础知识MD5算法简介Go语言概述Go中的MD5实现 crypto/md5 库的使用方法基本用法处理大型数据安全注意事项 实际案例分析示例1&#xff1a;文件的MD5校验示例2&#xff1a;网络数据的MD5哈希示例3…

专业课130+总分420+南京大学851信号与系统考研经验南大电子信息与通信系统

经过一年的复习&#xff0c;顺利上岸&#xff0c;被南京大学录取&#xff0c;今年专业课130&#xff0c;总分420&#xff0c;回忆这一年的复习还是有很多经验分享&#xff0c;希望对大家复习有帮助。 专业课&#xff1a; 南京大学851信号与系统难度这几年无论是范围还是难度都…

Java使用规范

1.关键字 定义&#xff1a;被Java语言赋予了特殊含义&#xff0c;用做专门用途的字符串(单词) 特点&#xff1a;关键字中的所有字母都是小写 2.保留字 java保留字&#xff1a;现有Java版本尚未使用&#xff0c;但以后的版本可能会作为关键字使用。命名标识符时要避免使用这些…

回归预测 | Matlab实现WOA-CNN-LSTM-Attention鲸鱼算法优化卷积长短期记忆网络注意力多变量回归预测(SE注意力机制)

回归预测 | Matlab实现WOA-CNN-LSTM-Attention鲸鱼算法优化卷积长短期记忆网络注意力多变量回归预测&#xff08;SE注意力机制&#xff09; 目录 回归预测 | Matlab实现WOA-CNN-LSTM-Attention鲸鱼算法优化卷积长短期记忆网络注意力多变量回归预测&#xff08;SE注意力机制&…

【Linux系统 01】Vim工具

目录 一、Vim概述 1. 文件打开方式 2. 模式切换 二、命令模式 1. 移动与跳转 2. 复制与粘贴 3. 剪切与撤销 三、编辑模式 1. 插入 2. 替换 四、末行模式 1. 保存与退出 2. 查找与替换 3. 分屏显示 4. 命令执行 一、Vim概述 1. 文件打开方式 vim 文件路径&#…