python绘制环境曲线 及箱型图

输入:

'''
Created on 2018年12月12日

@author: hcl
'''

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
 
file_path = 'Realtime_TH.csv'
msg = pd.read_csv(file_path)
# print(msg.shape)  #(1917, 6)
# print(msg.head())
# print(msg.tail())
X = range(msg.shape[0])
Y = msg['Temp']
plt.plot(X,Y)
plt.show()

结果:

 

将其按照时间绘制

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import datestr2num,DateFormatter
import matplotlib.dates as dates

file_path = 'Realtime_TH.csv'
msg = pd.read_csv(file_path)

Y = msg['Temp']
datess = msg['Time']

fig,ax=plt.subplots()
formatter = DateFormatter('%H')
#设置时间间隔
ax.xaxis.set_major_locator(dates.HourLocator(byhour=range(24), interval=1))
ax.xaxis.set_major_formatter(formatter)
ax.plot_date(datess,Y,'-',label='iops')

plt.show() 

输出:

 

输入:

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import datestr2num,DateFormatter
import matplotlib.dates as dates

# file_path = 'Realtime_TH.csv'
file_path = 'Realtime_NS.csv'
msg = pd.read_csv(file_path)

print(msg.head())
Y = msg['Temp']
Y_2 = msg['Hum']
datess = msg['Time']
 
fig,ax=plt.subplots()
formatter = DateFormatter('%H')
#设置时间间隔
ax.xaxis.set_major_locator(dates.HourLocator(byhour=range(24), interval=1))
ax.xaxis.set_major_formatter(formatter)
ax.plot_date(datess,Y,'-',label='NH3')
ax.plot_date(datess,Y_2,'-',label='H2S')
plt.legend() # 显示图例
plt.show() 

按照时间绘制NH3 H2S图片

 

环境数据异常值剔除

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import datestr2num,DateFormatter
import matplotlib.dates as dates

# file_path = 'Realtime_TH.csv'
file_path = 'Realtime_NS.csv'
msg = pd.read_csv(file_path)

print(msg.shape)
#寻找异常值索引
except_index = msg[msg['Hum'] > 1000].index.tolist()
except_index2 = msg[msg['Temp'] > 1000].index.tolist()    
msg = msg.drop(list(set(except_index).union(set(except_index2)))) 
msg.reset_index()
print(list(set(except_index).union(set(except_index2))))
print(msg.shape)
# print(msg[msg['Hum'] > 1000])
# print(msg.describe())
# print(msg.drop(msg['Temp'] > 1000))

# print(msg[msg['Hum'] > 1000])

Y = msg['Temp']
Y_2 = msg['Hum']
datess = msg['Time']
   
fig,ax=plt.subplots()
formatter = DateFormatter('%H')
#设置时间间隔
ax.xaxis.set_major_locator(dates.HourLocator(byhour=range(24), interval=1))
ax.xaxis.set_major_formatter(formatter)
ax.plot_date(datess,Y,'-',label='NH3')
ax.plot_date(datess,Y_2,'-',label='H2S')
plt.legend() # 显示图例
plt.show() 

输出:

(1413, 6)
[451, 454, 456, 786, 802, 746, 690]
(1406, 6)

 

绘制箱型图

输入:

import pandas as pd
import matplotlib.pyplot as plt
 
file_path = 'Realtime_TH.csv'
# file_path = 'Realtime_NS.csv'
msg = pd.read_csv(file_path)

msg.boxplot()
plt.legend() # 显示图例
plt.show() 

下图的temp和hum分别表示nh3 h2s  (因为在在存储数时,表头设置错误了)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值