def get_slopes(c,yrs,plot = False): """ get non-overlapping trends in concatenated control run """ trends = np.ma.array([]) start = 0 end = yrs if plot: Ntot = float(len(c)/yrs) while end < len(c): ctrunc = c[start:end] #if len(ctrunc.compressed()) == len(ctrunc): if True: # Express in "per decade" units. All control runs are in days. slope0,intercept0 = genutil.statistics.linearregression(ctrunc) slope = slope0*3650. if plot: xax = cmip5.get_plottable_time(ctrunc) plt.plot(xax,ctrunc.asma(),color = cm.RdYlBu(float(start/yrs)/Ntot)) plt.plot(xax,float(slope0)*ctrunc.getTime()[:]+float(intercept0),color ="k",linewidth = 3) trends = np.append(trends,slope) start = end end += yrs trends = MV.masked_where(np.isnan(trends),trends) trends = trends.compressed() return trends
def plot_ld(self, frame_idx, ld, title="Local Density Visualization", linked_plot=None): l_box = self.box_data[frame_idx] l_pos = self.pos_data[frame_idx] l_quat = self.quat_data[frame_idx] l_ang = 2 * np.arctan2(np.copy(l_quat[:, 3]), np.copy(l_quat[:, 0])) fbox = box.Box(Lx=l_box["Lx"], Ly=l_box["Ly"], is2D=True) side_length = max(fbox.Lx, fbox.Ly) l_min = -side_length / 2.0 l_min *= 1.1 l_max = -l_min if linked_plot is not None: x_range = linked_plot.x_range y_range = linked_plot.y_range else: x_range = (l_min, l_max) y_range = (l_min, l_max) # create array of transformed positions patches = local_to_global(verts, l_pos[:, 0:2], l_ang) # create an array of angles relative to the average # a = np.angle(psi_k) - np.angle(avg_psi_k) a = ld # turn into an rgb array of tuples # handle the matplotlib colormap myNorm = mplColors.Normalize(vmin=0.5, vmax=0.8) color = [tuple(cm.RdYlBu(myNorm(x))[:3]) for x in a] # bokeh (as of this version) requires hex colors, so convert rgb to hex hex_color = [ "#{:02x}{:02x}{:02x}".format(clamp(int(255 * r)), clamp(int(255 * g)), clamp(int(255 * b))) for (r, g, b) in color ] # plot p = figure(title=title, x_range=x_range, y_range=y_range, height=300, width=300) p.patches( xs=patches[:, :, 0].tolist(), ys=patches[:, :, 1].tolist(), fill_color=hex_color, line_color="black", ) default_bokeh(p) self.p = p return p
def all_annual_cycle(PET, i, j): nyears = PET.shape[0] / 12 years = np.arange(140) + 1 X, Y = np.meshgrid(years, years) thing = plt.pcolor(X, Y, X, cmap=cm.RdYlBu) thing.set_visible(False) plt.colorbar(orientation="horizontal", label="Year") [ plt.plot(PET.asma()[k * 12:(k + 1) * 12, i, j], color=cm.RdYlBu(k / float(nyears))) for k in range(nyears) ] months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ] plt.xticks(np.arange(12), months) plt.xlim(0, 11) plt.ylim(np.min(PET[:, i, j]), np.max(PET[:, i, j]))
def path(ax, shape, history): def pairwise(iterable): a, b = itertools.tee(iterable) next(b, None) return zip(a, b) k=0 for i,j in pairwise(range(len(history)-1)): xi = history[i][1][0] yi = history[i][1][1] zi = history[i][0] xj = history[j][1][0] yj = history[j][1][1] zj = history[j][0] x = [xi, xj] y = [yi, yj] z = [zi, zj] ax.plot(x,y,z, color=cm.RdYlBu(k)) k+=1
def plotBearing(self): """ Plot historgram of TC bearing as a polar diagram """ fig = pylab.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) theta = np.arange(0.0, 2*np.pi, np.pi/6.) bearing = (np.pi/2. - self.bearing * np.pi/180.) ii = np.where(bearing < 0) bearing[ii] += 2 * np.pi rads, bins = np.histogram(bearing, bins=12, range=(0., 2.*np.pi))#, new=True) bars = ax.bar(theta, rads, width=np.pi/6., bottom=0.0) [b.set_facecolor(cm.RdYlBu(float(r)/float(max(rads)))) for r, b in zip(rads, bars)] pylab.title('Cyclone Bearing', fontsize=10)
def __init__(self,image=np.zeros((1,1)), nColors=10,parent=None): QWidget.__init__(self,parent) self.nColors=nColors self.view= pg.GraphicsLayoutWidget() self.l = QVBoxLayout() self.setLayout(self.l) self.l.addWidget(self.view) self.show() self.w1 = self.view.addPlot() self.w1.vb.setAspectLocked(True,ratio=1) self.w1.vb.invertY(True) self.s1 = pg.ScatterPlotItem(size=5, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 120)) #self.s1.setData(x,y) self.w1.addItem(pg.ImageItem(image)) self.w1.addItem(self.s1) self.brush_idx=0 color=np.arange(self.nColors)/self.nColors color=np.array(cm.RdYlBu(color))*255 color[:,3]=200 # set alpha channel self.brushes=[pg.mkBrush(QColor(*color[i,:].astype(uint16))) for i in np.arange(self.nColors)]
# sessions n_sessions = 40 # subjects subs = ['subj0{}'.format(x + 1) for x in range(n_subjects)] # load labels labels = np.load(os.path.join(betas_dir, 'all_stims_category_labels.npy'), allow_pickle=True) # restrain to NSD images flat_labels = [item for sublist in labels for item in sublist] all_labels = sorted(list(set(flat_labels))) # get unique colour per category category_colors = cm.RdYlBu(range(80)) # which subjects are we dealing with? sub = subs[subject] # extract conditions data conditions = get_conditions(nsd_dir, sub, n_sessions) # we also need to reshape conditions to be ntrials x 1 conditions = np.asarray(conditions).ravel() # then we find the valid trials for which we do have 3 repetitions. conditions_bool = [ True if np.sum(conditions == x) == 3 else False for x in conditions ]
cmap=cm.RdYlBu bounds = np.linspace(-50,0,51) norm = colors.BoundaryNorm(bounds, cmap.N) #bounds = np.linspace(0,120,21) #norm = colors.BoundaryNorm(bounds, ncolors=256) #print norm(100) #sys.exit() for key, value in patches.iteritems(): print key+" "+str(color[key]) ax.add_collection(PatchCollection(value, facecolor=cm.RdYlBu(norm(color[key])), cmap=cm.RdYlBu, edgecolor='k', linewidth=1., zorder=2)) # ax.add_collection(PatchCollection(value, facecolors=color[key], cmap=cm.RdYlBu, edgecolor='k', # linewidth=1., zorder=2, norm=norm)) ### Plot colorbar #set room for colorbar fig.subplots_adjust(right = 0.85) axcb = fig.add_axes([0.87,0.15,0.03,0.7]) cb = mpl.colorbar.ColorbarBase(axcb, cmap=cmap, norm=norm, boundaries=bounds, orientation='vertical', ticks=np.linspace(-50,0,11))
def graphBars(self,treeDF): data = treeDF.replace(to_replace = "", value = 0) data = data[::-1] fig, ax = plt.subplots() index = data.index bar_width = 0.025 aux = 0 start = 8 end = 13 data_start = data.index.values[start] data_end = data.index.values[end-1] for month in data.columns[1:]: plt.bar(index.values[start:end]+bar_width*aux, data[month][data_start:data_end].values, bar_width, color=cm.RdYlBu(1.*aux/len(data.columns[1:])), edgecolor = 'w') aux += 1 labels = [] for i in index.values[start:end]: labels.append(i) plt.xlabel('Fed Funds Target Rate (Upper Bound)',fontsize = 18) plt.ylabel('Probability',fontsize = 18) plt.title('Fed Hike Implied Probability',fontsize = 20) plt.xticks(index[start:end]+0.1, labels,fontsize = 16) plt.yticks(fontsize = 16) plt.legend(data.columns[1:],fontsize = 14) plt.tight_layout() fig.set_size_inches(11.5, 7.5) plt.show()
# colors.append('white') #print pvalues[ backbone ][ fluct ] if pvalues[backbone][fluct] <= 0.05: #print "OK : " + str( pvalues[ backbone ][ fluct ] ) normalized_pvalues.append(pvalues[backbone][fluct]) else: #print "BAD: " + str( pvalues[ backbone ][ fluct ] ) normalized_pvalues.append(pvalues[backbone][fluct] + .3) z_values = [0] * len(bar_heights) ## z widths = [.5] * len(bar_heights) ## dx depths = [.5] * len(bar_heights) ## dy colors = [cm.RdYlBu(pval) for pval in normalized_pvalues] ax.bar3d(x_values, y_values, z_values, widths, depths, bar_heights, color=colors) m = cm.ScalarMappable(cmap=cm.RdYlBu) m.set_array(normalized_pvalues) cb = plt.colorbar(m, ticks=[0.4, 0.05, 0.01]) cb.ax.set_ylabel('P-Value') cb.set_ticklabels(ticklabels=['0.1', '0.05', '0.01'])
fig, axs = plt.subplots(n, n, subplot_kw=kws) surf = np.zeros_like(axs) Writer = animation.writers['ffmpeg'] writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800) for l in range(n): for m in range(n): if m <= l: f = abs((sphericalHarmonics(phi, theta, l, m)))**2 f = (f) / (np.max(f) - np.min(f)) surf[l][m] = axs[l][m].plot_surface(x, y, z, facecolors=cm.RdYlBu(f)) axs[l][m].set_axis_off() def update(angle): for l in range(n): for m in range(n): axs[l][m].view_init(10, angle * 5) return surf anim = animation.FuncAnimation(fig, update, interval=200, frames=2) anim.save("TUSL3D.mp4", extra_args=['-vcodec', 'libx264'])