def imu_hist_plot_multiple(x_vals, y_vals, z_vals): fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=set_size(width, subplot=[1, 3])) ax1.hist(np.array(x_vals), bins=280, edgecolor='black', color='#2ca02c') ax1.set_xlabel(r'Acceleration $(mm/{s^2})$') ax1.set_ylabel(r'Frequency') ax1.set_title(r'${a_x}_i$') ax1.set_xlim(-250.0, 250.0) ax2.hist(np.array(y_vals), bins=280, edgecolor='black', color='#ff7f0e') ax2.set_xlabel(r'Acceleration $(mm/{s^2})$') ax2.set_title(r'${a_y}_i$') ax2.set_xlim(-250.0, 250.0) # ax2.set_ylabel(r'Frequency') ax3.hist(np.array(z_vals), bins=800, edgecolor='black', color='#d62728') ax3.set_xlabel(r'Orientation $(deg)$') ax3.set_title(r'$\theta_i$') ax3.set_xlim(335, 385) # ax3.set_ylabel(r'Frequency') plt.subplots_adjust(wspace=0.5) plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/imu_hist_multiple.pdf', format='pdf', bbox_inches='tight')
def lidar_plots(data_scan, title): fig, (ax1, ax2) = plt.subplots(2, 1, figsize=set_size(width, subplot=[2, 1])) ax1.plot(data_scan, color='#1f77b4') ax1.set_xlabel(r'Angle $(deg)$') ax1.set_ylabel(r'Distance $(mm)$') ax1.set_title(r'Lidar Scan - Distance vs. Angle') x_pos = [] y_pos = [] x_lim = [] y_lim = [] max_range = 1792 for i, dist in enumerate(data_scan): radians = (i * np.pi / 180) x_pos.append(-1 * dist * np.sin(radians)) y_pos.append(-1 * dist * np.cos(radians)) ax2.scatter(x_pos, y_pos, c='#1f77b4') for i in range(360): radians = (i * np.pi / 180) x_lim.append(max_range * np.cos(radians)) y_lim.append(max_range * np.sin(radians)) ax2.scatter(x_lim, y_lim, c='#ff7f0e') ax2.set_xlabel(r'X (mm)') ax2.set_ylabel(r'Y (mm)') ax2.axis('equal') ax2.set_xlim(-2000, 2000) ax2.set_xlim(-2000, 2000) ax2.set_title(r'Lidar Scan - Real World Coordinates') plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/lidar_plot_{}.pdf' .format(title), format='pdf', bbox_inches='tight')
def position_plot(x_vals, y_vals, title): fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) ax1.scatter(x_vals, y_vals) ax1.set_title(r'Position Plot') plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/position_{}.pdf'. format(title), format='pdf', bbox_inches='tight')
def lidar_plot_raw_data(data_scan): fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) ax1.plot(data_scan, color='#1f77b4') ax1.set_xlabel(r'Angle $(deg)$') ax1.set_ylabel(r'Distance $(mm)$') ax1.set_title(r'Lidar Scan - Distance vs. Angle') plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/lidar_plot_raw_data.pdf', format='pdf', bbox_inches='tight')
def imu_time_plot(time_vals, data_vals, title, color='#d62728'): fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) ax1.plot(time_vals, data_vals, color=color) ax1.set_xlabel(r'Time $(s)$') ax1.set_ylabel(r'Orientation $(deg)$') ax1.set_title(title) plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/imu_plot_{}.pdf'. format(title), format='pdf', bbox_inches='tight')
def encoder_plot_lr(l_vals, r_vals): fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) ax1.plot(l_vals, label='Left Encoder') ax1.plot(r_vals, label='Right Encoder') ax1.set_xlabel(r'Samples') ax1.set_ylabel(r'Encoder Counts') ax1.legend() ax1.set_title(r'Quadrature Encoder Sample Data') plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/encoder_plot_lr.pdf', format='pdf', bbox_inches='tight')
def compare_plots(title, *args): fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) for i, data in enumerate(args): ax1.plot(data, label=i) ax1.legend() ax1.set_title(r'Kalman Filter - Comparison') ax1.set_xlabel(r'Samples') ax1.set_ylabel(r'Displacement (mm)') plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/compare_{}.pdf'. format(title), format='pdf', bbox_inches='tight')
def imu_hist_plot(data_vals, title, x_axis_limits=None, color='#1f77b4'): fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) ax1.hist(np.array(data_vals), bins=700, edgecolor='black', color=color) if x_axis_limits: ax1.set_xlim(x_axis_limits[0], x_axis_limits[1]) ax1.set_xlabel(r'Orientation $(deg)$') ax1.set_ylabel(r'Frequency') ax1.set_title(r'\theta_i') #plt.subplots_adjust(wspace = 0.4) plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/imu_hist_{}.pdf'. format(title), format='pdf', bbox_inches='tight')
def lr_odometry_pos_plot(l_vals, r_vals, x_vals, y_vals): fig, (ax1, ax2) = plt.subplots(1, 2, figsize=set_size(width, subplot=[1, 2])) ax1.plot(l_vals, label='Left Encoder') ax1.plot(r_vals, label='Right Encoder') ax1.set_xlabel(r'Samples') ax1.set_ylabel(r'Encoder Counts') ax1.legend() ax1.set_title(r'Quadrature Encoder Data') ax2.scatter(x_vals, y_vals) ax2.set_title(r'Odometry Model') ax2.set_xlabel(r'x-axis $(mm)$') ax2.set_ylabel(r'y-axis $(mm)$') plt.subplots_adjust(wspace=0.4) plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/lr_odometry_pos_plot.pdf', format='pdf', bbox_inches='tight')
def imu_time_plot_multiple(time_vals, x_vals, y_vals, z_vals): fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=set_size(width, subplot=[1, 3])) ax1.plot(time_vals, x_vals, color='#1f77b4') ax1.set_xlabel(r'Time $(s)$') ax1.set_ylabel(r'Acceleration $(m/{s^2})$') ax1.set_title(r'x-axis') ax2.plot(time_vals, y_vals, color='#ff7f0e') ax2.set_xlabel(r'Time $(s)$') ax2.set_title(r'y-axis') ax3.plot(time_vals, z_vals, color='#2ca02c') ax3.set_xlabel(r'Time $(s)$') ax3.set_title(r'z-axis') plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/imu_plot_multiple.pdf', format='pdf', bbox_inches='tight')
def lidar_plot_coords(x, y): fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) ax1.scatter(x, y, c='#1f77b4') ax1.scatter(0, 0, c='#2ca02c') ax1.arrow(0, 0, 100, 0) max_range = 1792 x_lim = [] y_lim = [] for i in range(360): radians = (i * np.pi / 180) x_lim.append(max_range * np.cos(radians)) y_lim.append(max_range * np.sin(radians)) ax1.scatter(x_lim, y_lim, c='#ff7f0e') ax1.set_xlabel(r'X (mm)') ax1.set_ylabel(r'Y (mm)') ax1.axis('equal') ax1.set_xlim(-2000, 2000) ax1.set_xlim(-2000, 2000) ax1.set_title(r'Lidar Scan - Real World Coordinates') plt.savefig( '/home/pi/BEng_Project/report_stuff/graph_formatting/lidar_coords_plot.pdf', format='pdf', bbox_inches='tight')
} mpl.rcParams.update(nice_fonts) ############################### print('Settings updated') #Figure Plotting###################### #Wake_bck_multiple# q = np.array(map(int,np.linspace(0,len(Tgrid)-1,3))) qreal=Tgrid[q]/(2*np.pi) eks=Xgrid/(2*np.pi) fig, axs = plt.subplots(3,1, figsize=set_size(subplots=(1.,1.))) subtxt=['(a)','(b)','(c)'] # Plot for i in range(len(q)): if i == range(len(q))[-1]: axs[i].set_xlabel('$x/\lambda_d$') axs[i].set_ylabel('$E_s/E^0_s$') axs[i].plot(eks,Eout[q[i]]) axs[i].set_xlim(50,160) axs[i].plot(eks,10*np.interp(Xgrid-vphi*Tgrid[q[i]]-push,ksigrid,Profile),'r',label='$n_e/\gamma_e$') axs[i].set_title('$\omega_d t = %.2f$' %qreal[i]) axs[i].legend(loc='lower right') axs[i].text(0.03,0.8,subtxt[i],transform=axs[i].transAxes) fig.tight_layout() plt.show()
pp = kastar.KinematicAStar(extents) #start = (randint(0, 10), randint(0, 10), np.radians(randint(0, 20))) #goal = (randint(40, 50), randint(40, 50), np.radians(randint(30, 50))) #path, moves, visited, obstacles_array = pp.plan_path(start, goal, obstacles) path, moves, visited, obstacles_array = pp.plan_path(start, goal, obstacles) print(path) print(moves) x_vals = [] y_vals = [] for node in path: x_vals.append(node[0]) y_vals.append(node[1]) fig, ax1 = plt.subplots(1, 1, figsize=set_size(width, subplot=[1, 1])) ax1.scatter(x_vals, y_vals, c='#ff7f0e') ax1.scatter(x_vals[0], y_vals[0], c='#2ca02c') ax1.scatter(x_vals[-1], y_vals[-1], c='#d62728') scalar = 3 dx_start = scalar * np.cos(start[2]) dy_start = scalar * np.sin(start[2]) dx_goal = scalar * np.cos(goal[2]) dy_goal = scalar * np.sin(goal[2]) ax1.arrow(x_vals[0], y_vals[0], dx_start, dy_start) ax1.arrow(x_vals[-1], y_vals[-1], dx_goal, dy_goal) ax1.set_xlabel(r'x-axis') ax1.set_xlim(0, extents[0]) ax1.set_ylim(0, extents[1])
from env_GR import kappa import IO # Parameters M, RNS, y_inner, comp, save, img = IO.load_params() # Available solutions Rphotkms = IO.get_phot_list() # Plotting import matplotlib.pyplot as plt from my_plot import set_size, plot_settings plot_settings() fig, ax = plt.subplots(1, 1, figsize=set_size('mnras2col')) save = 1 for i, R in enumerate(Rphotkms): r, rho, T, P, Linf = IO.read_from_file(R) Kap = kappa(rho, T) taustar = Kap * rho * r * 1e5 ax.loglog(r, taustar, 'r', linewidth=0.7) ax.set_xlabel('r (km)') ax.set_ylabel(r'$\tau^* = \kappa\rho r$') ax.axhline(3, color='k', linewidth=0.7, linestyle='--') ax.set_ylim([0.6, 1e3])
"legend.fontsize": 6, "xtick.labelsize": 6, "ytick.labelsize": 6, } mpl.rcParams.update(nice_fonts) ############################### print('Settings updated') #Figure Plotting###################### #Vacuum propagation# q = np.array(map(int, np.linspace(0, len(Tgrid) - 1, 3))) qreal = Tgrid[q] / (2 * np.pi) eks = Xgrid / (2 * np.pi) wy = Eout fig, axs = plt.subplots(1, 3, figsize=set_size(subplots=(1., 1.))) subtxt = ['(a)', '(b)', '(c)'] # Plot for i in range(len(q)): axs[i].axes.yaxis.set_visible(False) if i == 0: axs[i].set_ylabel('$E_s/E^0_s$') axs[i].axes.yaxis.set_visible(True) axs[i].plot(eks, wy[q[i]]) axs[i].set_xlabel('$x/ \lambda_d$') axs[i].set_title('$\omega_d t = %.2f$' % qreal[i]) axs[i].text(0.03, 0.95, subtxt[i], transform=axs[i].transAxes) plt.show() #fig.savefig('/home/christoffer/Thesis_MCs_figures/vacuumprop.pdf', format='pdf', bbox_inches='tight')
# Use 10pt font in plots, to match 10pt font in document "axes.labelsize": 8, "axes.titlesize": 8, "font.size": 8, # Make the legend/label fonts a little smaller "legend.fontsize": 6, "xtick.labelsize": 6, "ytick.labelsize": 6, } mpl.rcParams.update(nice_fonts) ############################### print('Settings updated') #Plot time series of Electron beam# eks = Xgrid / (2 * np.pi) fig, axs = plt.subplots(1, 4, figsize=set_size(subplots=(1., 1.))) subtxt = ['(a)', '(b)', '(c)', '(d)'] q = np.array(map(int, np.linspace(0, len(Tgrid) - 1, 4))) qreal = Tgrid[q] / (2 * np.pi) for i in range(len(q)): axs[i].set_xlabel('$x/\lambda_d$') axs[i].set_ylabel('$E_s/E^0_s$') axs[i].plot(eks, Eout[q[i]]) axs[i].plot(eks, 20 * neProf.gauss(Xgrid, Tgrid, vphi, Tgrid[q[i]], tgrow[q[i]], twid[q[i]],