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.7KB

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