plt.py 2.3 KB

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