Plot_trajectory.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon May 27 11:41:07 2024
  4. @author: michael.murzin
  5. """
  6. import matplotlib.pyplot as plt
  7. import numpy as np
  8. import pandas as pd
  9. import datetime
  10. initial_filename = 'traject.txt'
  11. downloaded_traject_filename = 'downloaded_nodes.txt'
  12. nodes = np.loadtxt('1.txt')
  13. points = np.loadtxt('downloaded_nodes')
  14. def analyze(interp_nodes, points):
  15. x = interp_nodes[:,0]
  16. y = interp_nodes[:,1]
  17. xx = np.array( range(x[-1]) )
  18. yy = np.interp(xx, x, y)
  19. diff = yy - points
  20. max_diff = np.max(diff)
  21. min_diff = np.min(diff)
  22. print( f'Min diff = {min_diff:.3f}, max diff = {max_diff:.3f}' )
  23. return yy
  24. def visualize(yy, points):
  25. ax1 = plt.subplot(211)
  26. plt.plot(points, label='uC')
  27. plt.grid()
  28. plt.plot( yy, 'r', label='PC' )
  29. plt.legend(loc='upper left')
  30. plt.subplot(212, sharex=ax1)
  31. plt.plot(yy - points, label='PC - uC')
  32. plt.grid()
  33. plt.legend(loc='upper left')
  34. plt.show()
  35. current_datetime = datetime.datetime.now()
  36. plt.savefig(f'Traject_comarison_{current_datetime}.png')
  37. yy = analyze(nodes, points)
  38. visualize(yy,points)