plt.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # time: 2024/4/26 11:53
  4. # file: plt.py
  5. # author: David
  6. # company: shenyang JY
  7. import matplotlib.pyplot as plt
  8. import numpy as np
  9. import pandas as pd
  10. import math
  11. tower = pd.read_csv('tower-1-process.csv')
  12. tower = tower.apply(pd.to_numeric, errors='ignore')
  13. powers = pd.read_csv('power.csv')
  14. tower['C_TIME'] = pd.to_datetime(tower['C_TIME'])
  15. powers['C_TIME'] = pd.to_datetime(powers['C_TIME'])
  16. union = pd.merge(powers, tower, on='C_TIME')
  17. predict_dt = tower.head(1)['C_TIME'][0]
  18. history_dt = tower.iloc[-1, :]["C_TIME"]
  19. if history_dt - predict_dt != pd.Timedelta(hours=1):
  20. print("环境数据-鉴权失败")
  21. union.set_index('C_TIME', inplace=True)
  22. # union = union.loc['2023-06-01': '2023-06-10']
  23. union = union.loc['2023-06']
  24. union.reset_index(inplace=True)
  25. union = union[['C_TIME', 'C_REAL_VALUE', 'C_WS_INST_HUB_HEIGHT']]
  26. union['C_TIME'] = pd.to_datetime(union['C_TIME'])
  27. # union.to_csv("./趋势对比1分钟.csv", index=False)
  28. union5, union_index = [], [0] # 功率表,索引表
  29. ps, wss = 0, 0
  30. for i, power in union.iterrows():
  31. real_value = power['C_REAL_VALUE']
  32. ws = power["C_WS_INST_HUB_HEIGHT"]
  33. ps += real_value
  34. wss += ws
  35. if str(power['C_TIME'].minute) in ('0', '15', '30', '45'):
  36. union_index.append(i)
  37. num = union_index[-1] - union_index[-2]
  38. num = num if num != 0 else 1
  39. psa = round(ps / num, 2)
  40. wsa = round(wss / num, 2)
  41. union5.append([power['C_TIME'], psa, wsa])
  42. ps = 0
  43. wss = 0
  44. union5 = pd.DataFrame(union5, columns=['C_TIME', 'C_REAL_VALUE', 'C_WS_INST_HUB_HEIGHT'])
  45. union5.rename(columns={'C_REAL_VALUE':"C_REAL_VALUE_AVE", 'C_WS_INST_HUB_HEIGHT': 'C_WS_INST_HUB_HEIGHT_AVE'}, inplace=True)
  46. union5['C_TIME'] = pd.to_datetime(union5['C_TIME'])
  47. UNION = pd.merge(union, union5, on='C_TIME', how='left')
  48. UNION.to_csv('./趋势对比union1.csv', index=False)
  49. fig, ax = plt.subplots()
  50. wss, rps, indexs = [], [], []
  51. indexs1, wss1, rps1 = [],[],[]
  52. UNION = UNION.iloc[:575, :]
  53. for index, row in UNION.iterrows():
  54. ws = round(row['C_WS_INST_HUB_HEIGHT']*1.5, 3)
  55. ws_ave = round(row['C_WS_INST_HUB_HEIGHT_AVE']*1.5, 3)
  56. rp = row['C_REAL_VALUE']
  57. rp_ave = row['C_REAL_VALUE_AVE']
  58. wss.append(ws)
  59. rps.append(rp)
  60. indexs.append(index)
  61. if not math.isnan(rp_ave):
  62. indexs1.append(index)
  63. wss1.append(ws_ave)
  64. rps1.append(rp_ave)
  65. ax.plot(indexs, rps, color='red', label='1minRP')
  66. ax.plot(indexs1, wss1, color='blue', label='15minWS')
  67. plt.legend()
  68. plt.savefig('./趋势对比4.png')