#!/usr/bin/env python # -*- coding: utf-8 -*- # time: 2024/4/26 11:53 # file: plt.py # author: David # company: shenyang JY import matplotlib.pyplot as plt import numpy as np import pandas as pd import math tower = pd.read_csv('./tower-1-process.csv') tower = tower.apply(pd.to_numeric, errors='ignore') powers = pd.read_csv('./power.csv') tower['C_TIME'] = pd.to_datetime(tower['C_TIME']) powers['C_TIME'] = pd.to_datetime(powers['C_TIME']) union = pd.merge(powers, tower, on='C_TIME') union.set_index('C_TIME', inplace=True) # union = union.loc['2023-06-01': '2023-06-10'] union = union.loc['2023-06'] union.reset_index(inplace=True) union = union[['C_TIME', 'C_REAL_VALUE', 'C_WS_INST_HUB_HEIGHT']] union['C_TIME'] = pd.to_datetime(union['C_TIME']) # union.to_csv("./趋势对比1分钟.csv", index=False) union5, union_index = [], [0] # 功率表,索引表 ps, wss = 0, 0 for i, power in union.iterrows(): real_value = power['C_REAL_VALUE'] ws = power["C_WS_INST_HUB_HEIGHT"] ps += real_value wss += ws if str(power['C_TIME'].minute) in ('0', '15', '30', '45'): union_index.append(i) num = union_index[-1] - union_index[-2] num = num if num != 0 else 1 psa = round(ps / num, 2) wsa = round(wss / num, 2) union5.append([power['C_TIME'], psa, wsa]) ps = 0 wss = 0 union5 = pd.DataFrame(union5, columns=['C_TIME', 'C_REAL_VALUE', 'C_WS_INST_HUB_HEIGHT']) union5.rename(columns={'C_REAL_VALUE':"C_REAL_VALUE_AVE", 'C_WS_INST_HUB_HEIGHT': 'C_WS_INST_HUB_HEIGHT_AVE'}, inplace=True) union5['C_TIME'] = pd.to_datetime(union5['C_TIME']) UNION = pd.merge(union, union5, on='C_TIME', how='left') UNION.to_csv('./趋势对比union1.csv', index=False) fig, ax = plt.subplots() wss, rps, indexs = [], [], [] indexs1, wss1, rps1 = [],[],[] UNION = UNION.iloc[:575, :] for index, row in UNION.iterrows(): ws = round(row['C_WS_INST_HUB_HEIGHT']*1.5, 3) ws_ave = round(row['C_WS_INST_HUB_HEIGHT_AVE']*1.5, 3) rp = row['C_REAL_VALUE'] rp_ave = row['C_REAL_VALUE_AVE'] wss.append(ws) rps.append(rp) indexs.append(index) if not math.isnan(rp_ave): indexs1.append(index) wss1.append(ws_ave) rps1.append(rp_ave) ax.plot(indexs, rps, color='red', label='1minRP') ax.plot(indexs1, wss1, color='blue', label='15minWS') plt.legend() plt.savefig('./趋势对比4.png')