def plotHPCP(signal, signalname, hpcp, w, speaks, frameSize, hopSize, figtitle, show=False): hpcp_, _, _, hpcpmean, hpcpmedian = extractHPCP(signal, frameSize, hopSize, w, speaks, hpcp, signal) fig = figure(num=None, figsize=(8, 5), dpi=80, facecolor='w', edgecolor='k') gs = GridSpec(4, 4) ax1 = subplot(gs[:, :-1]) ax2 = subplot(gs[:, -1]) ax1.imshow(hpcp_[::-1, :], aspect='auto') ax1.set_title(figtitle) ax2.plot(hpcpmean, xrange(36)) yticks(np.arange(36), np.arange(35, -1, -1)) locator_params(axis='x', nbins=4) tight_layout() if show: show() figname = figtitle + '.png' fig.savefig(figname, bbox_inches='tight') html = "<p><img src=\"" + figname + "\"></p>\n" return html
def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs): from matplotlib.pyplot import GridSpec, gcf fig = gcf() s1,s2 = shape subplotspec = GridSpec(s1, s2).new_subplotspec(loc, rowspan=rowspan, colspan=colspan) a = fig.add_subplot(subplotspec, **kwargs) bbox = a.bbox byebye = [] for other in fig.axes: if other==a: continue if bbox.fully_overlaps(other.bbox): byebye.append(other) for ax in byebye: delaxes(ax) return a
def __init__(self): # 공통 그래프 self.fig = plt.figure() self.gs = GridSpec(3, 1, figure=self.fig) self.fig_db = { 'PZRPres': [], 'PZRLevl': [], 'FV122': [], 'HV142': [], 'PZRSpray': [], 'PZRTemp': [], 'ExitCoreT': [], } self.axes = [ # Left self.fig.add_subplot(self.gs[0:1, :]), self.fig.add_subplot(self.gs[1:2, :]), self.fig.add_subplot(self.gs[2:3, :]), ]
noise = np.random.random(x.size) - 0.5 if i < 4: swipe.append(x + noise/(i+1)) else: swipe.append(x) swipe = np.array(swipe) # First trying to find median value average = np.median(swipe,axis=0) # Then see how coherent each signal is comparing to median fig1=figure(1) gs1=GridSpec(5,6) gs1.update(left=0.01,right=0.01) ax1=subplot2grid((5,6),(0,0),rowspan=4) for i in xrange(swipe.shape[0]): ax1.plot(t,swipe[i,:]+i) ax1.set_ylabel('RF number') ax2=subplot2grid((5,6),(4,0),colspan=1,rowspan=2) ax2.plot(t,average) ax2.set_title('Median RF') ax3=subplot2grid((5,6),(0,2),colspan=4,rowspan=3) for i in xrange(swipe.shape[0]):
def plot_and_save_results(ana, line_id="young_plume", date_fmt="%H:%M"): # plot colors for different optical flow retrievals cmap = get_cmap("Oranges") c_optflow_hybrid = cmap(255) c_optflow_histo = cmap(175) c_optflow_raw = cmap(100) fig = figure(figsize=(16, 12)) gs = GridSpec(4, 1, height_ratios=[.6, .2, .2, .2], hspace=0.05) ax3 = fig.add_subplot(gs[3]) ax0 = fig.add_subplot(gs[0], sharex=ax3) ax1 = fig.add_subplot(gs[1], sharex=ax3) ax2 = fig.add_subplot(gs[2], sharex=ax3) ax1.yaxis.tick_right() ax1.yaxis.set_label_position("right") ax3.yaxis.tick_right() ax3.yaxis.set_label_position("right") # Get emission rate results for the PCS line res0 = ana.get_results(line_id=line_id, velo_mode="glob") res1 = ana.get_results(line_id=line_id, velo_mode="flow_raw") res2 = ana.get_results(line_id=line_id, velo_mode="flow_histo") res3 = ana.get_results(line_id=line_id, velo_mode="flow_hybrid") res0.save_txt(join(SAVE_DIR, "ex12_flux_velo_glob.txt")) res1.save_txt(join(SAVE_DIR, "ex12_flux_flow_raw.txt")) res2.save_txt(join(SAVE_DIR, "ex12_flux_flow_histo.txt")) res3.save_txt(join(SAVE_DIR, "ex12_flux_flow_hybrid.txt")) # Plot emission rates for the different plume speed retrievals res0.plot(yerr=True, date_fmt=date_fmt, ls="-", ax=ax0, color="c", ymin=0, alpha_err=0.08) res1.plot(yerr=False, ax=ax0, ls="-", color=c_optflow_raw, ymin=0) res2.plot(yerr=False, ax=ax0, ls="--", color=c_optflow_histo, ymin=0) res3.plot(yerr=True, ax=ax0, lw=3, ls="-", color=c_optflow_hybrid, ymin=0) # ax[0].set_title("Retrieved emission rates") ax0.legend(loc='best', fancybox=True, framealpha=0.5, fontsize=12) ax0.grid() # Plot effective velocity retrieved from optical flow histogram analysis res3.plot_velo_eff(ax=ax1, date_fmt=date_fmt, color=c_optflow_hybrid) # ax[1].set_title("Effective plume speed # (from optflow histogram analysis)") ax1.set_ylim([0, ax1.get_ylim()[1]]) # Plot time series of predominant plume direction (retrieved from optical # flow histogram analysis and stored in object of type LocalPlumeProperties # which is part of plumespeed.py module ana.pcs_lines[line_id].plume_props.plot_directions(ax=ax2, date_fmt=date_fmt, color=c_optflow_hybrid) ax2.set_ylim([-180, 180]) pyplis.helpers.rotate_xtick_labels(ax=ax2) ax0.set_xticklabels([]) ax1.set_xticklabels([]) ax2.set_xticklabels([]) # tight_layout() ax3 = ana.plot_bg_roi_vals(ax=ax3, date_fmt="%H:%M") # gs.tight_layout(fig, h_pad=0)#0.03) gs.update(hspace=0.05, top=0.97, bottom=0.07) return fig
def plot_all_clusters(group_cats, outdir, plot_dir, wells=None, **kwargs): """ Plot clusters in map view, xsection and stress orientations :param group_cat: Catalog of events in the cluster :param outdir: Arnold-Townend output directory :param plot_dir: Output directory for plots :param kwargs: kwargs passed to plot_well_seismicity :return: """ # Just big loop over all clusters for i, cat in enumerate(group_cats): # Do some setting up of the plots based on wells if wells == 'Rotokawa': profile = [(176.185, -38.60), (176.21, -38.62)] xsection = [(176.185, -38.60), (176.21, -38.62)] else: # Figure out which wells to plot from median event latitude med_lat = np.median([ev.preferred_origin().latitude for ev in cat]) if med_lat > -38.55: # NgaN wells = ['NM08', 'NM09'] elif med_lat < -38.55: wells = ['NM06', 'NM10'] profile = 'EW' xsection = None if len(cat) < 10: print('Fewer than 10 events. Not plotting') continue clust_name = '{}_0'.format(i) # Set up subplots with gridspec fig = plt.figure(figsize=(12, 12)) gs = GridSpec(4, 4) #, hspace=0.1, wspace=0.1) ax_map = fig.add_subplot(gs[0:2, 0:2]) ax_xsec = fig.add_subplot(gs[2:, :]) ax_strs = fig.add_subplot(gs[0:2, 2:], polar=True) ax_map = plot_well_seismicity(cat, wells=wells, profile='map', ax=ax_map, xsection=xsection, color=False, **kwargs) ax_xsec = plot_well_seismicity(cat, wells=wells, profile=profile, ax=ax_xsec, color=False, **kwargs) try: ax_strs = plot_arnold_density(outdir=outdir, clust_name=clust_name, ax=ax_strs) except: print('Inversion output doesnt exist. Moving on.') continue plt.tight_layout() plt.savefig('{}/Cluster_{}.png'.format(plot_dir, clust_name), dpi=300, bbox='tight') plt.close('all') return
if color: Xc = tf.split(X, 3, axis=3) X = tf.concat([_new_phase_shift(x, r) for x in Xc], axis=3) else: X = _new_phase_shift(X, r) return X # Feature map with shape [1, 8, 8, 4] with each feature map i having value i x = np.ones((1, 8, 8, 4)) * np.arange(4)[None, None, None, :] # Convert to a [1, 16, 16, 1] Tensor y = tf.depth_to_space(tf.constant(x), 2) # Plot results figure(figsize=(12, 4.5)) gs = GridSpec(2, 5, width_ratios=[1, 1, 2, 2, 2]) for i in xrange(4): plt.subplot(gs[i // 2, i % 2]) plt.imshow(x[:, :, :, i].squeeze(), cmap=cm.jet, vmin=0, vmax=4, interpolation='nearest') # Add ticks at pixels, annoyingly have to offset by 0.5 to line up with pixels xticks(0.5 + np.arange(8)) yticks(0.5 + np.arange(8)) plt.gca().set_xticklabels([]) gca().set_yticklabels([]) plt.title('feature %d' % i) subplot(gs[:, 2]) print x.shape out_ps = PS(tf.constant(x), 2) imshow(tf.squeeze(out_ps).numpy(), cmap=cm.jet, vmin=0, vmax=4, interpolation='nearest') axis('off')