plt.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. union.set_index('C_TIME', inplace=True)
  18. # union = union.loc['2023-06-01': '2023-06-10']
  19. union = union.loc['2023-06']
  20. union.reset_index(inplace=True)
  21. union = union[['C_TIME', 'C_REAL_VALUE', 'C_WS_INST_HUB_HEIGHT']]
  22. union['C_TIME'] = pd.to_datetime(union['C_TIME'])
  23. # union.to_csv("./趋势对比1分钟.csv", index=False)
  24. union5, union_index = [], [0] # 功率表,索引表
  25. ps, wss = 0, 0
  26. for i, power in union.iterrows():
  27. real_value = power['C_REAL_VALUE']
  28. ws = power["C_WS_INST_HUB_HEIGHT"]
  29. ps += real_value
  30. wss += ws
  31. if str(power['C_TIME'].minute) in ('0', '15', '30', '45'):
  32. union_index.append(i)
  33. num = union_index[-1] - union_index[-2]
  34. num = num if num != 0 else 1
  35. psa = round(ps / num, 2)
  36. wsa = round(wss / num, 2)
  37. union5.append([power['C_TIME'], psa, wsa])
  38. ps = 0
  39. wss = 0
  40. union5 = pd.DataFrame(union5, columns=['C_TIME', 'C_REAL_VALUE', 'C_WS_INST_HUB_HEIGHT'])
  41. union5.rename(columns={'C_REAL_VALUE':"C_REAL_VALUE_AVE", 'C_WS_INST_HUB_HEIGHT': 'C_WS_INST_HUB_HEIGHT_AVE'}, inplace=True)
  42. union5['C_TIME'] = pd.to_datetime(union5['C_TIME'])
  43. UNION = pd.merge(union, union5, on='C_TIME', how='left')
  44. UNION.to_csv('./趋势对比union1.csv', index=False)
  45. fig, ax = plt.subplots()
  46. wss, rps, indexs = [], [], []
  47. indexs1, wss1, rps1 = [],[],[]
  48. UNION = UNION.iloc[:575, :]
  49. for index, row in UNION.iterrows():
  50. ws = round(row['C_WS_INST_HUB_HEIGHT']*1.5, 3)
  51. ws_ave = round(row['C_WS_INST_HUB_HEIGHT_AVE']*1.5, 3)
  52. rp = row['C_REAL_VALUE']
  53. rp_ave = row['C_REAL_VALUE_AVE']
  54. wss.append(ws)
  55. rps.append(rp)
  56. indexs.append(index)
  57. if not math.isnan(rp_ave):
  58. indexs1.append(index)
  59. wss1.append(ws_ave)
  60. rps1.append(rp_ave)
  61. ax.plot(indexs, rps, color='red', label='1minRP')
  62. ax.plot(indexs1, wss1, color='blue', label='15minWS')
  63. plt.legend()
  64. plt.savefig('./趋势对比4.png')