def set_cmap(self, cmap): """ Change the colormap of the image """ if cmap == 'autumn': plt.autumn() elif cmap == 'spring': plt.spring() self.canvas.show()
def main(): observations = [pfd_snr.Observation(pfdfn) for pfdfn in sys.argv[1:]] data = np.array([(o.snr, o.ra, o.dec) for o in observations]) if debug: print "data:" for z in data: print "\tSNR:", z[0], "RA:", z[1], "Dec:", z[2] # Init guess is max SNR, weighted avg of RA, weighted avg of Dec data_T = data.transpose() init_params = (data_T[0].max(), (data_T[0]*data_T[1]).sum()/data_T[0].sum(), \ (data_T[0]*data_T[2]).sum()/data_T[0].sum()) if debug: print "initial parameters:" print "\tSNR:", init_params[0], "RA:", init_params[1], "Dec:", init_params[2] global beam_profile # Use gain = 1 beam_profile = estimate_snr.EstimateFWHMSNR(3.35/2.0, 1420, 100, 2, 1, 24) result = fit(init_params, data) if debug: print "results:" print "\tSNR:", result[0], "RA:", result[1], "Dec:", result[2] psrsnr, psrra, psrdec = result snrs, ras, decs = data.transpose() plt.figure(figsize=(8.5,11)) plt.subplot(211) plt.title("Fitting gridding observations to determine pulsar position") plt.scatter((ras-psrra)*60/15.0, (decs-psrdec)*60, c=snrs, marker='o', label='_nolegend_') plt.spring() cbar = plt.colorbar() cbar.set_label(r"$SNR$") plt.scatter(np.array([0]), np.array([0]), s=100, c='k', marker=(5,1,0), \ label='Best PSR posn') if debug: plt.scatter(np.array([init_params[1]-psrra])*60/15.0, \ np.array([init_params[2]-psrdec])*60, \ s=100, c='w', marker=(5,1,0), label='Init PSR posn') plt.legend(loc='best') plt.xlabel("RA (sec) + %02.0f:%02.0f:%07.4f" % psr_utils.rad_to_hms(psrra/60.0*psr_utils.DEGTORAD)) plt.ylabel("Dec (arcsec) + %02.0f:%02.0f:%07.4f" % psr_utils.rad_to_dms(psrdec/60.0*psr_utils.DEGTORAD)) obsangseps = np.zeros(len(snrs)) for ii in range(len(snrs)): obsangseps[ii] = angsep_arcmin(psrra, psrdec, ras[ii], decs[ii]) maxangsep = obsangseps.max() angseps = np.linspace(0,maxangsep*1.1, 1000) plt.subplot(212) plt.plot(angseps, psrsnr*beam_profile.gain_at_angular_offset(angseps), 'k', zorder=-1) plt.scatter(obsangseps, snrs, c=snrs, zorder=1) plt.xlabel("Angular separation (arcmin)") plt.ylabel("SNR") plt.savefig('gridding.tmp.ps', papertype='letter', orientation='portrait') cid_keypress = plt.gcf().canvas.mpl_connect('key_press_event', \ keypress) plt.show()
def graph_plotting(dates_temperatures, city): plt.figure(figsize=(15, 7)) plt.bar(range(len(dates_temperatures)), [value - 273 for value in dates_temperatures.values()], align='edge', width=0.5, color='red') # Kelvins to Celsius plt.xticks(range(len(dates_temperatures)), list(dates_temperatures.keys())) plt.title('{} Weather Forecast {} - {}'.format( city, list(dates_temperatures.keys())[0], list(dates_temperatures.keys())[-1])) plt.tick_params(axis='x', rotation=70) plt.spring() plt.show()
def plot4DGraph(clusters): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') iter = 0 for cluster in clusters: u_val = [obj[0] for obj in clusters[cluster]] v_val = [obj[1] for obj in clusters[cluster]] w_val = [obj[2] for obj in clusters[cluster]] x_val = [obj[3] for obj in clusters[cluster]] if iter == 0: img1 = ax.scatter(u_val, v_val, w_val, s=75, c=x_val, cmap=plt.winter(), label='cluster1') cbar = fig.colorbar(img1, shrink=0.5, aspect=10) elif iter == 1: img2 = ax.scatter(u_val, v_val, w_val, s=75, c=x_val, cmap=plt.spring(), label='cluster2') cbar = fig.colorbar(img2, shrink=0.5, aspect=10) else: img3 = ax.scatter(u_val, v_val, w_val, s=75, c=x_val, cmap=plt.gray(), label='cluster3') cbar = fig.colorbar(img3, shrink=0.5, aspect=10) iter += 1 cbar.ax.get_yaxis().labelpad = 15 cbar.ax.set_ylabel('petal width in cm') cbar.ax.get_xaxis().labelpad = 15 cbar.ax.set_xlabel('cluster' + str(iter)) ax.set_xlabel('sepal length in cm', rotation=150) ax.set_ylabel('sepal width in cm') ax.set_zlabel(r'petal length in cm', rotation=60) plt.title("4D representation of clustering solution") plt.show()
t = data[:, 1] rvm = RVM() rvm.learn(X, t) print "a=", rvm.a # 描画 import matplotlib.pyplot as plt x = sp.linspace(0, 1, 50) # +-標準偏差1つ分の幅の表示 meshx, meshy = sp.meshgrid(sp.linspace(0, 1, 200), sp.linspace(-1.5, 1.5, 200)) meshz = [[abs(rvm.mean(meshx[j][i]) - meshy[j][i]) <= sp.sqrt(rvm.variance(meshx[j][i])) for i in range(len(meshx[0]))] for j in range(len(meshx))] plt.contour(meshx, meshy, meshz, 1) plt.spring() # 入力 plt.scatter(X, t, label="input") # 関連ベクトルの描画 plt.scatter(X[rvm.rv_index], t[rvm.rv_index], marker='d', color='r', label="relevance vector") # 元の曲線を表示 y = sp.sin(2*sp.pi*x) plt.plot(x, y, label="sin(2pix)") # RVMの予測の平均 y_ = [rvm.mean(xi) for xi in x] plt.plot(x, y_, label="RVM regression")
def main(): observations = [pfd_snr.Observation(pfdfn) for pfdfn in sys.argv[1:]] data = np.array([(o.snr, o.ra, o.dec) for o in observations]) if debug: print "data:" for z in data: print "\tSNR:", z[0], "RA:", z[1], "Dec:", z[2] # Init guess is max SNR, weighted avg of RA, weighted avg of Dec data_T = data.transpose() init_params = (data_T[0].max(), (data_T[0]*data_T[1]).sum()/data_T[0].sum(), \ (data_T[0]*data_T[2]).sum()/data_T[0].sum()) if debug: print "initial parameters:" print "\tSNR:", init_params[0], "RA:", init_params[ 1], "Dec:", init_params[2] global beam_profile # Use gain = 1 beam_profile = estimate_snr.EstimateFWHMSNR(3.35 / 2.0, 1420, 100, 2, 1, 24) result = fit(init_params, data) if debug: print "results:" print "\tSNR:", result[0], "RA:", result[1], "Dec:", result[2] psrsnr, psrra, psrdec = result snrs, ras, decs = data.transpose() plt.figure(figsize=(8.5, 11)) plt.subplot(211) plt.title("Fitting gridding observations to determine pulsar position") plt.scatter((ras - psrra) * 60 / 15.0, (decs - psrdec) * 60, c=snrs, marker='o', label='_nolegend_') plt.spring() cbar = plt.colorbar() cbar.set_label(r"$SNR$") plt.scatter(np.array([0]), np.array([0]), s=100, c='k', marker=(5,1,0), \ label='Best PSR posn') if debug: plt.scatter(np.array([init_params[1]-psrra])*60/15.0, \ np.array([init_params[2]-psrdec])*60, \ s=100, c='w', marker=(5,1,0), label='Init PSR posn') plt.legend(loc='best') plt.xlabel("RA (sec) + %02.0f:%02.0f:%07.4f" % psr_utils.rad_to_hms(psrra / 60.0 * psr_utils.DEGTORAD)) plt.ylabel("Dec (arcsec) + %02.0f:%02.0f:%07.4f" % psr_utils.rad_to_dms(psrdec / 60.0 * psr_utils.DEGTORAD)) obsangseps = np.zeros(len(snrs)) for ii in range(len(snrs)): obsangseps[ii] = angsep_arcmin(psrra, psrdec, ras[ii], decs[ii]) maxangsep = obsangseps.max() angseps = np.linspace(0, maxangsep * 1.1, 1000) plt.subplot(212) plt.plot(angseps, psrsnr * beam_profile.gain_at_angular_offset(angseps), 'k', zorder=-1) plt.scatter(obsangseps, snrs, c=snrs, zorder=1) plt.xlabel("Angular separation (arcmin)") plt.ylabel("SNR") plt.savefig('gridding.tmp.ps', papertype='letter', orientation='portrait') cid_keypress = plt.gcf().canvas.mpl_connect('key_press_event', \ keypress) plt.show()