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

news2024/11/27 1:57:14

目录

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_dist2

def good(pm):
    #优
    degree = pm-35
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 35
        else:
            degree[i] += 35
    return degree
def moderate(pm):
    #良
    degree = pm-35
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 40
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 40
        else:
            degree[i] += 40
    return degree
def lightlyP(pm):
    #轻度污染
    degree = pm-75
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 40
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 40
        else:
            degree[i] += 40
    return degree
def moderatelyP(pm):
    #中度污染
    degree = pm - 115
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 35
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 35
        else:
            degree[i] += 35
    return degree
def heavilyP(pm):
    #重度污染
    degree = pm - 150
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 100
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 100
        else:
            degree[i] += 100
    return 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_dist2

def good(pm):
    #优
    degree = pm-35
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 35
        else:
            degree[i] += 35
    return degree
def moderate(pm):
    #良
    degree = pm-35
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 40
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 40
        else:
            degree[i] += 40
    return degree
def lightlyP(pm):
    #轻度污染
    degree = pm-75
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 40
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 40
        else:
            degree[i] += 40
    return degree
def moderatelyP(pm):
    #中度污染
    degree = pm - 115
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 35
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 35
        else:
            degree[i] += 35
    return degree
def heavilyP(pm):
    #重度污染
    degree = pm - 150
    for i in range(len(degree)):
        if degree[i] < 0:
            degree[i] = 0
    degree -= 100
    for i in range(len(degree)):
        if degree[i] > 0:
            degree[i] = 100
        else:
            degree[i] += 100
    return 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.coloradmin.cn/o/1432899.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

arping交叉编译

arping命令依赖libpcap和libnet&#xff0c;需要先交叉编译这两个库。 1.交叉编译libpcap 下载libpcap源文件&#xff0c;从github上克隆: git clone https://github.com/the-tcpdump-group/libpcap.git source交叉编译环境 # environment-setup是本机的交叉编译环境, 里面…

12. onnx转为rknn测试时有很多重叠框的修改(python)

我们下载rknn-toolkit2-master后并进行前面的处理后&#xff0c;进入到rknn-toolkit2-master\examples\onnx\yolov5文件夹&#xff0c;里面有个test.py文件&#xff0c;打开该文件&#xff0c;其代码如下&#xff1a; # -*- coding: utf-8 -*- # coding:utf-8import os import…

解决问题(Tensorflow框架):ImportError: cannot import name ‘merge‘ from ‘keras.layers‘

看了一圈解决方案&#xff0c;没有找到跟我这个相关的 这就是版本兼容性问题 说句最简单的&#xff0c;针对我这个问题 直接把merge删除点就完事了&#xff0c;因为新版的tensorflow框架这个里面不包含merge&#xff0c;所以直接删掉问题就解决了

SD-WAN的安全性体现在哪里?

SD-WAN技术以其高度灵活、网络自动配置和低成本等优势&#xff0c;将多个物理WAN链接整合为一个逻辑网络&#xff0c;推动网络从“连通驱动”向“服务驱动”导向的转变。同时&#xff0c;企业在追求高效网络时&#xff0c;SD-WAN的安全性也成为一个重要的考量因素。 SD-WAN采用…

快速掌握西门子S7-1200 PLC的PID控制工艺

模拟量闭环控制系统-PID控制的特点&#xff1a; 不需要被控对象的数学模型&#xff0c;结构简单容易实现&#xff0c;使用方便有较强的灵活性和适应性。 用调试窗口整定PID控制器-调试窗口的功能&#xff1a; 1、使用“首次启动自调节”功能优化控制器 2、使用“运行中自调节…

windows 搭建nginx http服务

下载 下面链接直接点击下载&#xff0c;下载的就是包含rtmp服务器相关功能的&#xff0c;只不过需要配置下 Index of /download/ (ecsds.eu) nginx 1.7.11.3 Gryphon.zip直接点击额下面的连接即可下载 http://nginx-win.ecsds.eu/download/nginx%201.7.11.3%20Gryphon.zip …

问题:下列哪些属于历史文化资源的特征( ). #学习方法#学习方法

问题&#xff1a;下列哪些属于历史文化资源的特征( ). A、稀缺性 B、脆弱性 C、可再生性 D、多样性 参考答案如图所示

深度学习(7)---Diffusion Model概念讲解

文章目录 一、基本概括1.1 概念讲解1.2 Denoise模块 二、Stable Diffusion2.1 概念讲解2.2 FID2.3 CLIP 一、基本概括 1.1 概念讲解 1. Diffusion Model是一种生成模型&#xff0c;通过连续添加高斯噪声来破坏训练数据&#xff0c;然后学习反转的去噪过程来恢复数据。它分为正…

算法学习——华为机考题库10(HJ64 - HJ67)

算法学习——华为机考题库10&#xff08;HJ64 - HJ70&#xff09; HJ64 MP3光标位置 描述 MP3 Player因为屏幕较小&#xff0c;显示歌曲列表的时候每屏只能显示几首歌曲&#xff0c;用户要通过上下键才能浏览所有的歌曲。为了简化处理&#xff0c;假设每屏只能显示4首歌曲&a…

代码随想录算法训练营第三十五天|343. 整数拆分 , 96.不同的二叉搜索树

343. 整数拆分 代码随想录 视频讲解&#xff1a;动态规划&#xff0c;本题关键在于理解递推公式&#xff01;| LeetCode&#xff1a;343. 整数拆分_哔哩哔哩_bilibili class Solution {public int integerBreak(int n) {// 1.确定dp数组&#xff08;dp table&#xff09;以及下…

【git】本地项目推送到github、合并分支的使用

1. github上创建仓库信息 点击个人头像&#xff0c;选择【你的仓库】 点击【新增】 填写仓库信息 2. 本地项目执行的操作 1.生成本地的git管理 (会生成一个.git的文件夹) git init 2.正常提交到暂存区&#xff0c;并填写提交消息 git add . git commit -m "init…

golang并发安全-sync.Once

什么是sync.Once sync.Once 是 Go 语言中的一种同步原语&#xff0c;用于确保某个操作或函数在并发环境下只被执行一次。它只有一个导出的方法&#xff0c;即 Do&#xff0c;该方法接收一个函数参数。在 Do 方法被调用后&#xff0c;该函数将被执行&#xff0c;而且只会执行一…

Python算法题集_搜索二维矩阵II

Python算法题集_搜索二维矩阵II 题41&#xff1a;搜索二维矩阵II1. 示例说明2. 题目解析- 题意分解- 优化思路- 测量工具 3. 代码展开1) 标准求解【双层循环】2) 改进版一【行尾检测】3) 改进版二【对角线划分】 4. 最优算法 本文为Python算法题集之一的代码示例 题41&#xf…

Oracle 面试题 | 12.精选Oracle高频面试题

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…

国辰智企APS自动化排产平台:实现生产计划与其他系统无缝协同

在当今竞争激烈的制造环境中&#xff0c;有效的生产计划和排程对于企业的成功至关重要。APS生产计划排程平台作为一种先进的工具&#xff0c;正越来越受到企业的关注和应用。那么&#xff0c;APS生产计划排程平台有哪些类型呢&#xff1f;本文将为您详细介绍。 1.基于规则的APS…

Java学习-内部类

内部类概述 1.成员内部类 注意&#xff1a; 2.静态内部类 3.局部内部类&#xff08;看看就行&#xff09; 4.匿名内部类 应用场景&#xff1a;通常作为一个参数传给方法 Eg.小猫和小狗都参加游泳比赛

Open CASCADE学习|分割曲线

1、通过参数进行分割 分别获得曲线的 FirstParameter 和 LastParameter &#xff0c;然后对参数进行分割&#xff0c;获得n个ui&#xff0c;并对每个ui调用D0&#xff08;获得这个点的坐标值&#xff09;或D1&#xff08;获得这个点的坐标值和切向量&#xff09;。这个方法的优…

【MySQL进阶】事务原理

文章目录 事务机制基本介绍事务管理基本操作提交方式事务 ID 隔离级别四种级别加锁分析 原子特性实现方式实现原理undo log 隔离特性实现方式MVCC实现原理隐藏字段undo logRead View RC RR 持久特性实现方式redo log 一致特性 面试题MySQL的ACID特性分别是怎么实现的&#xff1…

AES算法:数据传输的安全保障

在当今数字化时代&#xff0c;数据安全成为了一个非常重要的问题。随着互联网的普及和信息技术的发展&#xff0c;我们需要一种可靠的加密算法来保护我们的敏感数据。Advanced Encryption Standard&#xff08;AES&#xff09;算法应运而生。本文将介绍AES算法的优缺点、解决了…

React 中实现拖拽功能-插件 react-beautiful-dnd

拖拽功能在平时开发中是很常见的&#xff0c;这篇文章主要使用react-beautiful-dnd插件实现此功能。 非常好用&#xff0c;附上GitHub地址&#xff1a;https://github.com/atlassian/react-beautiful-dnd 安装及引入 // 1.引入 # yarn yarn add react-beautiful-dnd# npm npm…