我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pylab.pcolormesh()。
def plot_colormeshmatrix_reduced( X, Y, ymin = None, ymax = None, title = "plot_colormeshmatrix_reduced"): print "plot_colormeshmatrix_reduced X.shape", X.shape, "Y.shape", Y.shape # input_cols = [i for i in df.columns if i.startswith("X")] # output_cols = [i for i in df.columns if i.startswith("Y")] # Xs = df[input_cols] # Ys = df[output_cols] # numsamples = df.shape[0] # print "plot_scattermatrix_reduced: numsamples = %d" % numsamples # # numplots = Xs.shape[1] * Ys.shape[1] # # print "numplots = %d" % numplots cbar_orientation = "vertical" # "horizontal" gs = gridspec.GridSpec(Y.shape[2], X.shape[2]/2) pl.ioff() fig = pl.figure() fig.suptitle(title) # # alpha = 1.0 / np.power(numsamples, 1.0/(Xs.shape[1] - 0)) # alpha = 0.2 # print "alpha", alpha # cols = ["k", "b", "r", "g", "c", "m", "y"] for i in range(X.shape[2]/2): for j in range(Y.shape[2]): # print "i, j", i, j, Xs, Ys ax = fig.add_subplot(gs[j, i]) pcm = ax.pcolormesh(X[:,:,i], X[:,:,X.shape[2]/2+i], Y[:,:,j], vmin = ymin, vmax = ymax) # ax.plot(Xs.as_matrix()[:,i], Ys.as_matrix()[:,j], "ko", alpha = alpha) ax.set_xlabel("goal") ax.set_ylabel("error") cbar = fig.colorbar(mappable = pcm, ax=ax, orientation=cbar_orientation) ax.set_aspect(1) if SAVEPLOTS: fig.savefig("fig_%03d_colormeshmatrix_reduced.pdf" % (fig.number), dpi=300) fig.show()
def _plot_features(out_dir, signal, sampling_rate, logmel, delta, delta_delta, specgram, filename): try: os.makedirs(out_dir) except: pass sampling_interval = 1.0 / sampling_rate times = np.arange(len(signal)) * sampling_interval pylab.clf() plt.rcParams['font.size'] = 18 pylab.figure(figsize=(len(signal) / 2000, 16)) ax1 = pylab.subplot(511) pylab.plot(times, signal) pylab.title("Waveform") pylab.xlabel("Time [sec]") pylab.ylabel("Amplitude") pylab.xlim([0, len(signal) * sampling_interval]) ax2 = pylab.subplot(512) specgram = np.log(specgram) pylab.pcolormesh(np.arange(0, specgram.shape[0]), np.arange(0, specgram.shape[1]) * 8000 / specgram.shape[1], specgram.T, cmap=pylab.get_cmap("jet")) pylab.title("Spectrogram") pylab.xlabel("Time [sec]") pylab.ylabel("Frequency [Hz]") pylab.colorbar() ax3 = pylab.subplot(513) pylab.pcolormesh(np.arange(0, logmel.shape[0]), np.arange(1, 41), logmel.T, cmap=pylab.get_cmap("jet")) pylab.title("Log mel filter bank features") pylab.xlabel("Frame") pylab.ylabel("Filter number") pylab.colorbar() ax4 = pylab.subplot(514) pylab.pcolormesh(np.arange(0, delta.shape[0]), np.arange(1, 41), delta.T, cmap=pylab.get_cmap("jet")) pylab.title("Deltas") pylab.xlabel("Frame") pylab.ylabel("Filter number") pylab.colorbar() ax5 = pylab.subplot(515) pylab.pcolormesh(np.arange(0, delta_delta.shape[0]), np.arange(1, 41), delta_delta.T, cmap=pylab.get_cmap("jet")) pylab.title("Delta-deltas") pylab.xlabel("Frame") pylab.ylabel("Filter number") pylab.colorbar() pylab.tight_layout() pylab.savefig(os.path.join(out_dir, filename), bbox_inches="tight")
def densityPlot(targ_ra, targ_dec, data, iso, g_radius, nbhd, type): """Stellar density plot""" mag_g = data[mag_g_dred_flag] mag_r = data[mag_r_dred_flag] if type == 'stars': filter = star_filter(data) plt.title('Stellar Density') elif type == 'galaxies': filter = galaxy_filter(data) plt.title('Galactic Density') elif type == 'blue_stars': filter = blue_star_filter(data) plt.title('Blue Stellar Density') iso_filter = (iso.separation(mag_g, mag_r) < 0.1) # projection of image proj = ugali.utils.projector.Projector(targ_ra, targ_dec) x, y = proj.sphereToImage(data[filter & iso_filter]['RA'], data[filter & iso_filter]['DEC']) # filter & iso_filter bound = 0.5 #1. steps = 100. bins = np.linspace(-bound, bound, steps) signal = np.histogram2d(x, y, bins=[bins, bins])[0] sigma = 0.01 * (0.25 * np.arctan(0.25*g_radius*60. - 1.5) + 1.3) # full range, arctan convolution = scipy.ndimage.filters.gaussian_filter(signal, sigma/(bound/steps)) plt.pcolormesh(bins, bins, convolution.T, cmap='Greys') plt.xlim(bound, -bound) plt.ylim(-bound, bound) plt.gca().set_aspect('equal') plt.xlabel(r'$\Delta \alpha$ (deg)') plt.ylabel(r'$\Delta \delta$ (deg)') ax = plt.gca() divider = make_axes_locatable(ax) cax = divider.append_axes('right', size = '5%', pad=0) plt.colorbar(cax=cax)
def hessPlot(targ_ra, targ_dec, data, iso, g_radius, nbhd): """Hess plot""" mag_g = data[mag_g_dred_flag] mag_r = data[mag_r_dred_flag] filter_s = star_filter(data) plt.title('Hess') c1 = SkyCoord(targ_ra, targ_dec, unit='deg') r_near = 2.*g_radius # annulus begins at 3*g_radius away from centroid r_far = np.sqrt(5.)*g_radius # annulus has same area as inner area inner = (c1.separation(SkyCoord(data['RA'], data['DEC'], unit='deg')).deg < g_radius) outer = (c1.separation(SkyCoord(data['RA'], data['DEC'], unit='deg')).deg > r_near) & (c1.separation(SkyCoord(data['RA'], data['DEC'], unit='deg')).deg < r_far) xbins = np.arange(-0.5, 1.1, 0.1) ybins = np.arange(16., 24.5, 0.5) foreground = np.histogram2d(mag_g[inner & filter_s] - mag_r[inner & filter_s], mag_g[inner & filter_s], bins=[xbins, ybins]) background = np.histogram2d(mag_g[outer & filter_s] - mag_r[outer & filter_s], mag_g[outer & filter_s], bins=[xbins, ybins]) fg = foreground[0].T bg = background[0].T fg_abs = np.absolute(fg) bg_abs = np.absolute(bg) mask_abs = fg_abs + bg_abs mask_abs[mask_abs == 0.] = np.nan # mask signficiant zeroes signal = fg - bg signal = np.ma.array(signal, mask=np.isnan(mask_abs)) # mask nan cmap = matplotlib.cm.viridis cmap.set_bad('w', 1.) plt.pcolormesh(xbins, ybins, signal, cmap=cmap) plt.colorbar() ugali.utils.plotting.drawIsochrone(iso, lw=2, c='k', zorder=10, label='Isocrhone') plt.axis([-0.5, 1.0, 16, 24]) plt.gca().invert_yaxis() plt.gca().set_aspect(1./4.) plt.xlabel('g-r (mag)') plt.ylabel('g (mag)') #ax = plt.gca() #divider = make_axes_locatable(ax) #cax = divider.append_axes('right', size = '5%', pad=0) #plt.colorbar(cax=cax)