import matplotlib.pyplot as plt import numpy as np import os #plt.style.use('seaborn-darkgrid') font = {"family":"serif", "color":"black", "size":15} class Plotting: def __init__(self): self.useless = 0 def plot_antennas(self, data_path, antenna_list, scaling_factor): data = np.load('recorded_data/' + data_path + ".npy") data = data * scaling_factor fvs = data[:, 3:] antenna_dict = {"f1": 0, "f2": 1, "f3": 2, "f4": 3, "f5": 4, "f6": 5, "f7": 6, "f8": 7, "m1": 8, "m2": 9, "m3": 10, "m4": 11, "m5": 12, "m6": 13, "m7": 14, "m8": 15} label_iter = iter(["Frame 1", "Frame 2", "Frame 3", "Frame 4", "Frame 5", "Frame 6", "Frame 7", "Frame 8"]) markers = iter(['o', '8', 'p', '>', 'd', 'H', 'x', 'v', '^', '*', 'D', 's', 'h', '+', '<']) linestyles = iter(['-', '--', '-.', ':', '-', '--', '-.', ':']) colors = iter(["black", "black", "black", "black", "grey", "grey", "grey", "grey"]) # Plot the Antennas x = np.arange(np.shape(data)[0]) for antenna in antenna_list: y = fvs[:, antenna_dict[antenna]] plt.scatter(x, y, label=next(label_iter), marker=next(markers), s=5) plt.legend(bbox_to_anchor=(1.01, 1.00), loc=2, borderaxespad=0., fontsize=10) plt.title("Noise investigation") plt.ylabel('Receoving coil signals [V]', fontdict=font) plt.xlabel('Samples', fontdict=font) plt.show() def plot_positions(self, positions_path): # Load positions first positions = np.load("calculated_positions/"+positions_path+".npy") fig = plt.figure(figsize=[24, 9]) ax1 = plt.subplot2grid((1, 2), (0, 1)) ax2 = plt.subplot2grid((1, 2), (0, 0)) plt.subplots_adjust(left=0.07, bottom=0.07, right=0.89, top=0.89, wspace=0.2, hspace=0.2) # Set Axis ax1.set_xlim([-0.02, 0.52]) ax1.set_ylim([-0.02, 0.52]) ax1.set_xticks(np.arange(0.0, 0.55, 0.05)) ax1.set_yticks(np.arange(0.0, 0.55, 0.05)) ax1.set_xlabel('X-Position of object [m]', fontdict=font) ax1.set_ylabel('Y-Position of object [m]', fontdict=font) ax1.grid(alpha=0.6) for label in ax1.xaxis.get_ticklabels(): label.set_rotation(90) ax2.set_ylim([0.1, 0.6]) ax2.set_xlim([0.0, 0.2]) ax2.set_yticks(np.arange(-0.05, 0.65, 0.05)) ax2.set_xticks(np.arange(0.00, 0.20, 0.01)) ax2.set_ylabel('Y-Position of object [m]', fontdict=font) ax2.set_xlabel('Z-Position of object [m]', fontdict=font) ax2.grid(alpha=0.5) for label in ax2.xaxis.get_ticklabels(): label.set_rotation(90) # Set Titles ax1.set_title("XY", fontdict=font) ax2.set_title("ZY", fontdict=font) # Actual plotting ax1.plot(positions[:, 0], positions[:, 1], color="r", label="Position", linewidth=5, marker="x") ax2.plot(positions[:, 2], positions[:, 1], color="r", linewidth=5, marker="x") # CONFIGURE X, Y PLOT # Add the legend for different data plot lines # data_legend = plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.) # data_legend = plt.gca().add_artist(data_legend) # Indicate Exciter Exciter = ax1.vlines(x=0.0, ymin=0.0, ymax=0.5, linestyles="-", colors="#5b9bd5", label="Exciter", linewidth=6) ax1.vlines(x=0.5, ymin=0.0, ymax=0.5, linestyles="-", colors="#5b9bd5", linewidth=6) ax1.hlines(y=0.0, xmin=0.0, xmax=0.5, linestyles="-", colors="#5b9bd5", linewidth=6) ax1.hlines(y=0.5, xmin=0.0, xmax=0.5, linestyles="-", colors="#5b9bd5", linewidth=6) # Indicate Localization Area # LocArea = ax1.vlines(x=0.045, ymin=0.045, ymax=0.495, linestyles="dashed", colors="#7f7f7f", # label="Loc.\nArea") # ax1.vlines(x=0.495, ymin=0.045, ymax=0.495, linestyles="dashed", colors="#7f7f7f") # ax1.hlines(y=0.045, xmin=0.045, xmax=0.495, linestyles="dashed", colors="#7f7f7f") # ax1.hlines(y=0.495, xmin=0.045, xmax=0.495, linestyles="dashed", colors="#7f7f7f") # SHOW ANTENNAS 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, ... AntPosY = [0.125, 0.375, 0.5, 0.5, 0.125, 0.375, 0, 0] AntOrientY = [270, 270, 180, 180, 90, 90, 0, 0] # analog as AntPosX,Y , just with Orientation degrees (direction in z-axis # Select Antenna plotting options here patchAlpha = 1.0 # ITERATE THROUGH CMAP------------- n = 8 # color = iter(cm.jet(np.linspace(0, 1, n))) # ---------------------------- for i in range(8): # iterate through antennas x = AntPosX[i] # get x and y pos of antennas y = AntPosY[i] # c = next(color) # Comment in for coloured antennas c = "k" # black antennas if i == 7: # only print one label for the Antennas (otherwise its 8 times in legend) label = label = str("Receiving\nCoils") else: label = "" if AntOrientY[i] == 0: # identify antennas orientation patchX = float(x - 0.033 / 2) patchY = float(y - 0.033 / 2) rect = plt.Rectangle((patchX, patchY), 0.033, 0.033, color=c, alpha=patchAlpha, label=label) ax1.add_patch(rect) if AntOrientY[i] == 180: patchX = float(x - 0.033 / 2) patchY = float(y - 0.033 / 2) rect = plt.Rectangle((patchX, patchY), 0.033, 0.033, color=c, alpha=patchAlpha) ax1.add_patch(rect) if AntOrientY[i] == 90: patchX = float(x - 0.033 / 2) patchY = float(y - 0.033 / 2) rect = plt.Rectangle((patchX, patchY), 0.033, 0.033, color=c, alpha=patchAlpha) ax1.add_patch(rect) if AntOrientY[i] == 270: patchX = float(x - 0.033 / 2) patchY = float(y - 0.033 / 2) rect = plt.Rectangle((patchX, patchY), 0.033, 0.033, color=c, alpha=patchAlpha) ax1.add_patch(rect) # Add second Legend for hardware ax1.legend(handles=[Exciter, rect], bbox_to_anchor=(1.01, 0.11), loc=2, borderaxespad=0.) #ax1.legend(handles=[Position], bbox_to_anchor=(1.95, 0.11), loc=2, borderaxespad=0.) plt.show()