for data in reader: x2.append(int(data[0])) y2.append(int(data[1])) ############################################################################## # Plot some figures ############################################################################## # fig1 = plt.figure('fig1', figsize=(5, 5)) # ax1 = fig1.add_subplot(1, 1, 1) # fig1.patch.set_facecolor(cs['mdk_dgrey']) # ax1.set_xlabel('x axis') # ax1.set_ylabel('y axis') # plt.imshow(im, extent=prd.extents(x) + prd.extents(y)) fig2 = plt.figure('fig2', figsize=(5, 3)) ax2 = fig2.add_subplot(1, 1, 1) fig2.patch.set_facecolor(cs['mdk_dgrey']) ax2.set_xlabel('Year') ax2.xaxis.set_major_locator(MaxNLocator(integer=True)) ax2.set_ylabel('# of publications') plt.plot(x2, y2, '.:', label='free space') plt.plot(x0, y0, '.:', label='fibre') plt.plot(x1, y1, '.:', label='satellite') plt.legend(fancybox=True, framealpha=0.0) os.chdir(r"D:\Python\Misc Plots") plt.tight_layout() plt.show() prd.PPT_save_2d(fig2, ax2, 'plot1.png')
# cm = plt.get_cmap('binary') # surf0 = ax0.plot_surface(X[:, 0:a], Y[:, 0:a], Z1[ # :, 0:a], cmap='gray', alpha=0.6) # wire0 = ax0.plot_wireframe(X[:, 0:a], Y[:, 0:a], Z1[ # :, 0:a], color=cs['mdk_dgrey'], lw=0.5, alpha=1) fig1 = plt.figure('fig1') ax1 = fig1.add_subplot(1, 1, 1) fig1.patch.set_facecolor(cs['mdk_dgrey']) ax1.set_xlabel('x axis') ax1.set_ylabel('y axis') ax1.set_aspect(1) plt.imshow(Gtot, extent=(x[0], x[-1], y[0], y[-1]), origin='lower') # surffit = ax1.contour(*coords, G, 5 , cmap=cm.jet) plt.plot(xc, yc) # im3 = plt.figure('im3') # ax3 = im3.add_subplot(1, 1, 1) # im3.patch.set_facecolor(cs['mdk_dgrey']) # ax3.set_xlabel('x axis') # ax3.set_ylabel('y axis') # plt.imshow(im) # cb2 = plt.colorbar() # plt.legend() plt.tight_layout() plt.show() prd.PPT_save_2d(fig1, ax1, 'Hex pack.png')
# plt.plot(H1[0, :], 'o:') # plt.plot(H2[0, :], 'o:') # plt.ylim(0, 255) # plt.plot(ϕ1, 'o:') # plt.plot(Z12_mod[0, :] / π, 'o:') # plt.ylim(-1, 2) # plt.imshow(Z12_mod, extent=prd.extents(X) + prd.extents(Y)) # plt.imshow(H2, extent=prd.extents(X) + prd.extents(Y), # cmap='gray', vmin=0, vmax=255) # plt.colorbar() plt.plot(X, H2[0, :] / π, 'o:') # plt.plot(H2[0, :], Z_HR_mod[0, :] / π) ax1.set_xlabel('x axis - px') # ax1.set_ylabel('y axis - phase/π') # ax1.set_ylabel('y axis - phase (ϕ)') # im3 = plt.figure('im3') # ax3 = im3.add_subplot(1, 1, 1) # im3.patch.set_facecolor(cs['mdk_dgrey']) # ax3.set_xlabel('x axis') # ax3.set_ylabel('y axis') # plt.imshow(im) # cb2 = plt.colorbar() # plt.legend() plt.tight_layout() plt.show() os.chdir(f2) prd.PPT_save_2d(fig1, ax1, 'plot1.png')
'P$_{sat}$ = ' + str(P_sat) + 'μW' ############################################################################## # Plot some figures ############################################################################## fig2 = plt.figure('fig2', figsize=(6, 4)) prd.ggplot() ax2 = fig2.add_subplot(1, 1, 1) fig2.patch.set_facecolor(cs['mnk_dgrey']) ax2.set_xlabel('Inferred power (mW)') ax2.set_ylabel('kcounts per secound') plt.plot(Ps, kcps, 'o:', label='data') plt.plot(Ps_fit, Isat_fit, '-', label=lb0) plt.plot(Ps_fit, prd.I_sat(Ps_fit, popt[0], popt[1], 0, popt[3]), '--', label=lb1) plt.plot(Ps_fit, prd.I_sat(Ps_fit, 0, popt[1], popt[2], popt[3]), '--', label=lb2) ax2.legend(loc='upper left', fancybox=True, framealpha=1) os.chdir(p0) plt.title(lb3) plt.tight_layout() plt.show() ax2.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0)) prd.PPT_save_2d(fig2, ax2, 'Sat curve.png')
x1 = -τ * np.log(y1) + τ ############################################################################## # Plot some figures ############################################################################## prd.ggplot() # fig1 = plt.figure('fig1', figsize=(5, 5)) # ax1 = fig1.add_subplot(1, 1, 1) # fig1.patch.set_facecolor(cs['mnk_dgrey']) # ax1.set_xlabel('x axis') # ax1.set_ylabel('y axis') # plt.imshow(im, extent=prd.extents(x) + prd.extents(y)) size = 2 fig2 = plt.figure('fig2', figsize=(size * np.sqrt(2), size)) ax2 = fig2.add_subplot(1, 1, 1) fig2.patch.set_facecolor(cs['mnk_dgrey']) ax2.set_xlabel('x axis') ax2.set_ylabel('y axis') plt.plot(x1, y1, '.', alpha=0.4, color=cs['gglred'], label='') plt.plot(x1, y1, alpha=1, color=cs['ggdred'], lw=0.5, label='decay') plt.plot(x2, y2, '.', alpha=0.4, color=cs['gglblue'], label='') plt.plot(x2, y2, alpha=1, color=cs['ggblue'], lw=0.5, label='excite') ax2.legend(loc='upper right', fancybox=True, framealpha=0.5) # os.chdir(p0) plt.tight_layout() plt.show() ax2.legend(loc='upper right', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0)) plot_file_name = p0 + r'\plot1.png' prd.PPT_save_2d(fig2, ax2, plot_file_name)
for i0, val0 in enumerate(datafiles[4:]): x, y, img = prd.load_SCM_F5L10(val0) print(y) lb = os.path.basename(val0) print(lb, np.shape(img)) img_name = os.path.splitext(lb)[0] + '_img.png' profile_name = os.path.splitext(lb)[0] + '_prof.png' fig1 = plt.figure('fig1', figsize=(4, 4)) ax1 = fig1.add_subplot(1, 1, 1) fig1.patch.set_facecolor(cs['mnk_dgrey']) ax1.set_xlabel('x dimension (px)') ax1.set_ylabel('y dimension (px)') plt.imshow(img, label=lb) plt.gca().invert_yaxis() ax1.legend(loc='upper right', fancybox=True, framealpha=1) fig2 = plt.figure('fig2', figsize=(8, 4)) ax2 = fig2.add_subplot(1, 1, 1) fig2.patch.set_facecolor(cs['mnk_dgrey']) ax2.set_xlabel('x dimension (V)') ax2.set_ylabel('counts') plt.plot(img[10, :], '.:', label='y V = ' + str(round(y[-10], 4))) ax2.legend(loc='upper right', fancybox=True, framealpha=1) plt.show() os.chdir(p0) prd.PPT_save_2d(fig1, ax1, img_name) prd.PPT_save_2d(fig2, ax2, profile_name)
XT = d3 - d2 fig1 = plt.figure('fig1') ax1 = fig1.add_subplot(1, 1, 1) fig1.patch.set_facecolor(cs['mdk_dgrey']) ax1.set_xlabel('P1 - sin(ϕ) offset') ax1.set_ylabel('P0 - sin(ϕ) amplitude') plt.imshow(XT, aspect='auto', interpolation='none', extent=prd.extents(x) + prd.extents(y), origin='lower') plt.colorbar() fig2 = plt.figure('fig2') ax2 = fig2.add_subplot(1, 1, 1) fig2.patch.set_facecolor(cs['mdk_dgrey']) ax2.set_xlabel('P1 - sin(ϕ) offset') ax2.set_ylabel('P0 - sin(ϕ) amplitude') plt.imshow(d3, aspect='auto', interpolation='none', extent=prd.extents(x) + prd.extents(y), origin='lower') plt.colorbar() plt.show() os.chdir(p0) prd.PPT_save_2d(fig1, ax1, 'figure1')
sys.path.insert(0, r"D:\Python\Local Repo\library") import useful_defs_prd as prd cs = prd.palette() ############################################################################## # Do some stuff ############################################################################## p0 = (r"D:\Experimental Data\Oscilloscope (F5 L10)\SPAD outputs" r"\SPAD2.csv") lb = os.path.basename(p0) name = os.path.splitext(p0)[0] csv = np.genfromtxt(p0, delimiter=",") t = 1e6 * csv[:, 3] V = csv[:, 4] # plot each data set and save (close pop-up to save each time) prd.ggplot() fig1 = plt.figure('fig1', figsize=(6, 4)) ax1 = fig1.add_subplot(1, 1, 1) fig1.patch.set_facecolor(cs['mnk_dgrey']) ax1.set_xlabel('time / μs') ax1.set_ylabel('Voltage / V') ax1.plot(t, V, lw=0.5) ax1.plot(t, V, '.', markersize=0.3, alpha=0.5, label=lb) plt.title('time trace') plt.tight_layout() ax1.legend(loc='upper left', fancybox=True, framealpha=0.5) plt.show() ax1.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0)) prd.PPT_save_2d(fig1, ax1, name)
im2.patch.set_facecolor(cs['mdk_dgrey']) ax2.set_xlabel('x axis') ax2.set_ylabel('y axis') plt.imshow(H5, cmap='gray') # im3 = plt.figure('im3') # ax3 = im3.add_subplot(1, 1, 1) # im3.patch.set_facecolor(cs['mdk_dgrey']) # ax3.set_xlabel('x axis') # ax3.set_ylabel('y axis') # plt.imshow(H6, cmap='gray') # cb3 = plt.colorbar() # fig2 = plt.figure('fig2') # ax2 = Axes3D(fig2) # fig2.patch.set_facecolor(cs['mdk_dgrey']) # ax2.w_xaxis.set_pane_color(cs['mdk_dgrey']) # ax2.w_yaxis.set_pane_color(cs['mdk_dgrey']) # ax2.w_zaxis.set_pane_color(cs['mdk_dgrey']) # ax2.set_xlabel('x axis') # ax2.set_ylabel('y axis') # ax2.set_zlabel('z axis') # scat2 = ax2.scatter(X, Y, Z0, # '.', cmap='gray', s=16, c=Z0) # surf2 = ax2.plot_surface(X, Y, Z0, cmap='gray', alpha=0.1, edgecolor=ggred) plt.show() prd.PPT_save_2d(fig1, ax1, 'pixel row grey.png')
for i1, val1 in enumerate(files[0:]): print('file name = ', val1) data = io.loadmat(val1) if int(data['fibre']) > 4: fibre = str(int(data['fibre'])) else: fibre = str(int(data['fibre'])) label = 'Port ' + fibre fibre_c = 'fibre9d_' + fibre print(fibre) print(np.transpose(np.shape(data['Ps']))) plt.plot(np.transpose(data['lambdas']), np.transpose(data['Ps']), '-', lw=1, label=label, c=cs[fibre_c]) leg1 = plt.legend(prop={'size': 6}) leg1.get_frame().set_alpha(0.0) for text in leg1.get_texts(): text.set_color("black") ############################################################################## # Plot some figures ############################################################################## os.chdir(p2) plt.show() prd.PPT_save_2d(fig1, ax1, 'Port2')
ax2.set_xlabel('Count rate') ax2.set_ylabel('Freq (#)') lb1 = 'kcps 1 = ' + str(np.round(Cts1_μ/1e3,1)) lb2 = 'kcps 2 = ' + str(np.round(Cts2_μ/1e3,1)) lb3 = 'kcps$_{tot}$ = ' + str(np.round((Cts1_μ + Cts2_μ)/1e3,1)) Cts1_n, Cts1_bins, Cts1_patches = plt.hist(Cts1, bins=10, label=lb1, alpha=0.5, edgecolor=cs['mnk_dgrey']) Cts2_n, Cts2_bins, Cts2_patches = plt.hist(Cts2, bins=10, label=lb2, alpha=0.5, edgecolor=cs['mnk_dgrey']) Cts3_n, Cts3_bins, Cts3_patches = plt.hist(Cts2 + Cts1, bins=10, label=lb3, alpha=0.5, edgecolor=cs['mnk_dgrey']) x1, y1 = prd.Gauss_hist(Cts1) x2, y2 = prd.Gauss_hist(Cts2) x3, y3 = prd.Gauss_hist(Cts1 + Cts2) plt.plot(x1, y1, '-', linewidth=2, color=cs['ggred']) plt.plot(x2, y2, '-', linewidth=2, color=cs['ggblue']) plt.plot(x3, y3, '-', linewidth=2, color=cs['ggpurple']) ax2.legend(loc='upper left', fancybox=True, framealpha=0.2) os.chdir(p0) plt.tight_layout() plt.show() ax2.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.3)) prd.PPT_save_2d(fig2, ax2, 'hists.png')
# Optimized parameters print(res.x) scale = res.x[0] angle = res.x[1] ex = res.x[2] ey = res.x[3] print('Scale =', np.round(scale, 3)) print('Angle =', np.round(angle * 180 / pi, 2)) print('ex =', np.round(ex, 3)) print('ey =', np.round(ey, 3)) # Calculate theoretical positions x_theory, y_theory, error = calculate(scale, angle, ex, ey, x, y) print('error = ', np.round(error, 3)) # Plot data fig1 = plt.figure('fig1') ax1 = fig1.add_subplot(1, 1, 1) fig1.patch.set_facecolor(cs['mdk_dgrey']) ax1.set_xlabel('x axis') ax1.set_ylabel('y axis') plt.plot(x, y, 'o') plt.plot(x_theory, y_theory, '+') show() prd.PPT_save_2d(fig1, ax1, '2D array fit 1')
fig3 = plt.figure('fig3', figsize=(4, 4)) ax3 = fig3.add_subplot(1, 1, 1) fig3.patch.set_facecolor(cs['mdk_dgrey']) plt.plot(Profile1/π, '.:', c=cs[fibre_c]) ax3.set_ylabel('phase - / π') ax3.set_xlabel('x axis - px') plt.tight_layout() fig4 = plt.figure('fig4', figsize=(4, 4)) ax4 = fig4.add_subplot(1, 1, 1) fig4.patch.set_facecolor(cs['mdk_dgrey']) ax4.set_ylabel('y axis - px') ax4.set_xlabel('x axis - px') l5 = plt.imshow(H2[:, :], cmap='binary') # l6 = plt.plot(ϕ1 / π, g_ϕ1(ϕ1), '.') # l6 = plt.plot(ϕ1 / π, g_ϕ3(ϕ1)) # datacursor(l1, bbox=dict(fc=cs['mdk_yellow'], alpha=1)) # datacursor(l4, bbox=dict(fc=cs['mdk_yellow'], alpha=1)) plt.tight_layout() plt.show() os.chdir(p1) prd.PPT_save_2d(fig1, ax1, 'plot1.png') prd.PPT_save_2d(fig2, ax2, 'plot2.png') prd.PPT_save_2d(fig3, ax3, 'plot3.png') prd.PPT_save_2d(fig4, ax4, 'plot4.png')
ax5.set_ylabel('y axis - μm') ax5.set_xlabel('x axis - μm') fig6 = plt.figure('fig6', figsize=(4, 4)) fig6.patch.set_facecolor(cs['mdk_dgrey']) ax6 = fig6.add_subplot(1, 1, 1) ax6.set_ylabel('y axis - μm') ax6.set_xlabel('x axis - μm') fig7 = plt.figure('fig7', figsize=(4, 4)) fig7.patch.set_facecolor(cs['mdk_dgrey']) ax7 = fig7.add_subplot(1, 1, 1) ax7.set_ylabel('y axis - μm') ax7.set_xlabel('x axis - μm') I, x, y = prd.holo_replay_file(files[1], p1) np.savetxt(p0 + r'\I.csv', I, delimiter=',') np.savetxt(p0 + r'\x.csv', x, delimiter=',') np.savetxt(p0 + r'\y.csv', y, delimiter=',') plt.show() os.chdir(p0) prd.PPT_save_2d(fig1, ax1, 'plot1.png') prd.PPT_save_2d(fig2, ax2, 'plot2.png') prd.PPT_save_2d(fig3, ax3, 'plot3.png') prd.PPT_save_2d(fig4, ax4, 'plot4.png') prd.PPT_save_2d(fig5, ax5, 'plot5.png') prd.PPT_save_2d(fig6, ax6, 'plot6.png') prd.PPT_save_2d(fig7, ax7, 'plot7.png')
############################################################################## # Plot some figures ############################################################################## prd.ggplot() plot_path = r"D:\Python\Plots\\" plot_label = 'Gaussian wavepacket b' plot_file_name = plot_path + plot_label # fig1 = plt.figure('fig1', figsize=(5, 5)) # ax1 = fig1.add_subplot(1, 1, 1) # fig1.patch.set_facecolor(cs['mdk_dgrey']) # ax1.set_xlabel('x axis') # ax1.set_ylabel('y axis') # plt.imshow(im, extent=prd.extents(x) + prd.extents(y)) ### fig1 = plt.figure('fig1', figsize=(5, 5)) ax1 = fig1.add_subplot(1, 1, 1) fig1.patch.set_facecolor(cs['mnk_dgrey']) ax1.set_xlabel('x axis') ax1.set_ylabel('y axis') plt.plot(ts, Es, '-') plt.tight_layout() plt.axis('off') ### plt.savefig(plot_file_name + '.svg') plt.show() prd.PPT_save_2d(fig1, ax1, plot_file_name + '.png')
############################################################################## p1 = r"C:\Users\Philip\Documents\Powerpoints\IEEE Yangzhou" p2 = (r"C:\Users\Philip\Documents\Technical Stuff\Hologram optimisation" r"\High frequency sin term\180228\Sin amp values") f1 = p2 + r'\*.csv' files = glob.glob(f1) data_all = np.array([]) print(files) for i1, val1 in enumerate(files[:]): print(i1) data = np.genfromtxt(val1, delimiter=',') print(np.shape(data)) fig1 = plt.figure('fig1') ax1 = fig1.add_subplot(1, 1, 1) fig1.patch.set_facecolor(cs['mdk_dgrey']) ax1.set_xlabel('Frequency (GHz)') ax1.set_ylabel('Signal (dB)') plt.plot(1.0 * data[0, :], data[1, :], '-', lw=1, c=cs['ggred']) ax1.set_ylim([-70, -25]) plt.show() os.chdir(p2) prd.PPT_save_2d(fig1, ax1, str(i1)) # leg1 = plt.legend() # leg1.get_frame().set_alpha(0.0) ############################################################################## # Plot some figures ##############################################################################