You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plot_results.py 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import os
  4. plt.style.use('seaborn-darkgrid')
  5. font = {"family":"serif",
  6. "color":"black",
  7. "size":15}
  8. class Plotting:
  9. def __init__(self):
  10. self.useless = 0
  11. def plot_antennas(self, data_path, antenna_list):
  12. data = np.load('recorded_data/' + data_path + ".npy")
  13. fvs = data[:, 3:]
  14. antenna_dict = {"f1": 0, "f2": 1, "f3": 2, "f4": 3, "f5": 4, "f6": 5, "f7": 6, "f8": 7,
  15. "m1": 8, "m2": 9, "m3": 10, "m4": 11, "m5": 12, "m6": 13, "m7": 14, "m8": 15}
  16. # Plot the Antennas
  17. x = np.arange(np.shape(data)[0])
  18. for antenna in antenna_list:
  19. y = fvs[:, antenna_dict[antenna]]
  20. plt.plot(x, y, label=str(antenna))
  21. plt.legend()
  22. plt.show()
  23. def plot_positions(self, positions_path):
  24. # Load positions first
  25. positions = np.load("calculated_positions/"+positions_path+".npy")
  26. print(np.shape(positions))
  27. fig = plt.figure(figsize=[24, 9])
  28. ax1 = plt.subplot2grid((1, 2), (0, 1))
  29. ax2 = plt.subplot2grid((1, 2), (0, 0))
  30. plt.subplots_adjust(left=0.07, bottom=0.07, right=0.89, top=0.89, wspace=0.2, hspace=0.2)
  31. # Set Axis
  32. ax1.set_xlim([0.1, 0.54])
  33. ax1.set_ylim([0.1, 0.54])
  34. ax1.set_xticks(np.arange(0.0, 0.55, 0.05))
  35. ax1.set_yticks(np.arange(0.0, 0.55, 0.05))
  36. ax1.set_xlabel('X-Position of object [m]', fontdict=font)
  37. ax1.set_ylabel('Y-Position of object [m]', fontdict=font)
  38. ax1.grid(alpha=1.0)
  39. for label in ax1.xaxis.get_ticklabels():
  40. label.set_rotation(90)
  41. ax2.set_ylim([0.1, 0.6])
  42. ax2.set_xlim([0.0, 0.2])
  43. ax2.set_yticks(np.arange(-0.05, 0.65, 0.05))
  44. ax2.set_xticks(np.arange(0.00, 0.20, 0.01))
  45. ax2.set_ylabel('Y-Position of object [m]', fontdict=font)
  46. ax2.set_xlabel('Z-Position of object [m]', fontdict=font)
  47. ax2.grid(alpha=1.0)
  48. for label in ax2.xaxis.get_ticklabels():
  49. label.set_rotation(90)
  50. # Set Titles
  51. ax1.set_title("XY", fontdict=font)
  52. ax2.set_title("ZY", fontdict=font)
  53. # Actual plotting
  54. Position = ax1.plot(positions[:, 0], positions[:, 1], color="r", label="Position", linewidth=1)
  55. ax2.plot(positions[:, 2], positions[:, 1], color="r")
  56. # CONFIGURE X, Y PLOT
  57. # Add the legend for different data plot lines
  58. data_legend = plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.)
  59. data_legend = plt.gca().add_artist(data_legend)
  60. # Indicate Exciter
  61. Exciter = ax1.vlines(x=0.0, ymin=0.0, ymax=0.54, linestyles="-", colors="#5b9bd5", label="Exciter", linewidth=12)
  62. ax1.vlines(x=0.54, ymin=0.0, ymax=0.54, linestyles="-", colors="#5b9bd5", linewidth=12)
  63. ax1.hlines(y=0.0, xmin=0.0, xmax=0.54, linestyles="-", colors="#5b9bd5", linewidth=12)
  64. ax1.hlines(y=0.54, xmin=0.0, xmax=0.54, linestyles="-", colors="#5b9bd5", linewidth=12)
  65. # Indicate Localization Area
  66. LocArea = ax1.vlines(x=0.045, ymin=0.045, ymax=0.495, linestyles="dashed", colors="#7f7f7f",
  67. label="Loc.\nArea")
  68. ax1.vlines(x=0.495, ymin=0.045, ymax=0.495, linestyles="dashed", colors="#7f7f7f")
  69. ax1.hlines(y=0.045, xmin=0.045, xmax=0.495, linestyles="dashed", colors="#7f7f7f")
  70. ax1.hlines(y=0.495, xmin=0.045, xmax=0.495, linestyles="dashed", colors="#7f7f7f")
  71. # SHOW ANTENNAS
  72. AntPosX = [0.025, 0.025, 0.15, 0.40, 0.515, 0.515, 0.40,
  73. 0.15] # Safing each Antennas Position in a list -> e.g. : X position of frame ant 1, X pos of frame ant 2, x pos of frame ant 3, ...
  74. AntPosY = [0.15, 0.40, 0.515, 0.515, 0.40, 0.15, 0.025, 0.025] # analog as AntPosX
  75. AntOrientY = [270, 270, 180, 180, 90, 90, 0,
  76. 0] # analog as AntPosX,Y , just with Orientation degrees (direction in z-axis
  77. # Select Antenna plotting options here
  78. patchAlpha = 1.0
  79. # ITERATE THROUGH CMAP-------------
  80. n = 8
  81. # color = iter(cm.jet(np.linspace(0, 1, n)))
  82. # ----------------------------
  83. for i in range(8): # iterate through antennas
  84. x = AntPosX[i] # get x and y pos of antennas
  85. y = AntPosY[i]
  86. # c = next(color) # Comment in for coloured antennas
  87. c = "k" # black antennas
  88. if i == 7: # only print one label for the Antennas (otherwise its 8 times in legend)
  89. label = label = str("Receiving\nCoils")
  90. else:
  91. label = ""
  92. if AntOrientY[i] == 0:
  93. # identify antennas orientation
  94. patchX = float(x - 0.04 / 2)
  95. patchY = float(y - 0.04 / 2)
  96. rect = plt.Rectangle((patchX, patchY), 0.04, 0.04,
  97. color=c, alpha=patchAlpha, label=label)
  98. ax1.add_patch(rect)
  99. if AntOrientY[i] == 180:
  100. patchX = float(x - 0.04 / 2)
  101. patchY = float(y - 0.04 / 2)
  102. rect = plt.Rectangle((patchX, patchY), 0.04, 0.04,
  103. color=c, alpha=patchAlpha)
  104. ax1.add_patch(rect)
  105. if AntOrientY[i] == 90:
  106. patchX = float(x - 0.04 / 2)
  107. patchY = float(y - 0.04 / 2)
  108. rect = plt.Rectangle((patchX, patchY), 0.04, 0.04,
  109. color=c, alpha=patchAlpha)
  110. ax1.add_patch(rect)
  111. if AntOrientY[i] == 270:
  112. patchX = float(x - 0.04 / 2)
  113. patchY = float(y - 0.04 / 2)
  114. rect = plt.Rectangle((patchX, patchY), 0.04, 0.04,
  115. color=c, alpha=patchAlpha)
  116. ax1.add_patch(rect)
  117. # Add second Legend for hardware
  118. ax1.legend(handles=[Exciter, LocArea, rect], bbox_to_anchor=(1.01, 0.11), loc=2, borderaxespad=0.)
  119. #ax1.legend(handles=[Position], bbox_to_anchor=(1.95, 0.11), loc=2, borderaxespad=0.)
  120. plt.show()