def errorArea(xaxis, bin_up, bin_down, fillcolor='blue', hatch=None, hatchcolor='green', **kwargs): if hatch == None: hatchcolor = 'none' if xaxis[-1] == inf: xbin = xaxis[-2] - xaxis[-3] xaxis[-1] = xaxis[-2] + xbin xlim([xaxis[0], xaxis[-1]]) fill_xaxis = repeat(xaxis, 2)[1:-1] fill_bins_up = repeat(bin_up, 2) fill_bins_down = repeat(bin_down, 2) return fill_between(fill_xaxis, fill_bins_up, fill_bins_down, facecolor=fillcolor, edgecolor=hatchcolor, hatch=hatch, **kwargs)
def stackedBarPlot(xaxis, hist_list, colors = ['C0','C1','C2','C3','C4','C5'], linewidth = 1, fill = True, outer_line = True, hatch = [None]*6, zorder = -9, data_axis = 0, relative = False, **kwargs): bin_array = array(hist_list) cumsum_axis = 0 # Do the cumulative sum of the data bins_cumsum = insert(cumsum(bin_array, axis = cumsum_axis), 0, zeros(len(xaxis)-1), cumsum_axis) if relative: bins_cumsum /= bins_cumsum[-1, :] # Fix the xaxis original_xaxis = xaxis if xaxis[-1] == inf: xbin = xaxis[-2] - xaxis[-3] xaxis[-1] = xaxis[-2] + xbin xlim([xaxis[0], xaxis[-1]]) fill_xaxis = repeat(xaxis,2)[1:-1] areas = [] lines = [] rectangles = [] print('Cumsum results ', sum(bins_cumsum, axis = 1)) nhistograms = bins_cumsum.shape[cumsum_axis] for index in range(1, bins_cumsum.shape[cumsum_axis]): if outer_line: lines.append(unfilledBar(original_xaxis, bins_cumsum[index, :], color = colors[index-1], linewidth = linewidth)) lwbox = 1 else: lwbox = 0 #lines.append(unfilledBar(original_xaxis, bins_cumsum[:, index], color = colors[index-1], label = labels[index-1])) if hatch[index-1]: facecolor = 'white' else: facecolor = colors[index-1] if fill: areas.append( fill_between(repeat(xaxis,2)[1:-1], repeat(bins_cumsum[index,:],2), repeat(bins_cumsum[index-1,:],2), zorder = zorder-nhistograms+index, linewidth = 0, facecolor=facecolor, edgecolor = colors[index-1], hatch = hatch[index-1], **kwargs )) rectangles.append(matplotlib.patches.Rectangle((0,0), 1, 1, fc = facecolor, linewidth=2, zorder = zorder-1, edgecolor = colors[index-1], hatch = hatch[index-1])) return lines, areas, rectangles
def errorHatch(xaxis, bin_up, bin_down, hatch = '/', fillcolor = 'blue', **kwargs): if xaxis[-1] == inf: xbin = xaxis[-2] - xaxis[-3] xaxis[-1] = xaxis[-2] + xbin xlim([xaxis[0], xaxis[-1]]) fill_xaxis = repeat(xaxis,2)[1:-1] fill_bins_up = repeat(bin_up,2) fill_bins_down = repeat(bin_down, 2) return fill_between(fill_xaxis , fill_bins_up, fill_bins_down, edgecolor = hatchcolor, hatch = hatch, rasterized = True, **kwargs)
def plot_upd_impz(self, fig, taps, a=1): if not signal: return self.plot_init_impz(fig) ax1, ax2 = fig.get_axes() l = len(taps) impulse = pylab.repeat(0.,l); impulse[0] =1. x = arange(0,l) response = signal.lfilter(taps,a,impulse) ax1.stem(x, response) step = pylab.cumsum(response) ax2.stem(x, step)
def plot_upd_impz(self, fig, taps, a=1): if not signal: return self.plot_init_impz(fig) ax1, ax2 = fig.get_axes() l = len(taps) impulse = pylab.repeat(0., l) impulse[0] = 1. x = arange(0, l) response = signal.lfilter(taps, a, impulse) ax1.stem(x, response) step = pylab.cumsum(response) ax2.stem(x, step)
def snakeScan(centre=(0, 0), range=(10e-6, 10e-6), spacing=(1.0e-6, 1.0e-6)): from pylab import arange, concatenate, repeat if len(spacing) == 1: spacing = (spacing, spacing) # define some grids xgrid = arange(20, 31) ygrid = arange(10, 16) xscan = concatenate([xgrid[:: (-1) ** i] for i in range(len(ygrid))]) yscan = repeat(ygrid, len(xgrid)) return list(zip(a, b))
def _ichroma(self, V, **kwargs): """ :: Inverse chromagram transform. Make a signal from a folded constant-Q transform. """ if not (self._have_hcqft or self._have_cqft): return None a,b = self.HCQFT.shape if self._have_hcqft else self.CQFT.shape complete_octaves = a/self.nbpo # integer division, number of complete octaves if P.remainder(a,self.nbpo): complete_octaves += 1 X = P.repeat(V, complete_octaves, 0)[:a,:] # truncate if necessary X /= X.max() X *= P.atleast_2d(P.linspace(1,0,X.shape[0])).T # weight the spectrum self.x_hat = self._icqft(X, **kwargs) return self.x_hat
def impz(b,a=1): ''' #Plot step and impulse response from http://mpastell.com/2010/01/18/fir-with-scipy/ ''' l = len(b) impulse = pylab.repeat(0.,l); impulse[0] =1. x = numpy.arange(0,l) response = signal.lfilter(b,a,impulse) pylab.subplot(211) pylab.stem(x, response) pylab.ylabel('Amplitude') pylab.xlabel(r'n (samples)') pylab.title(r'Impulse response') pylab.subplot(212) step = numpy.cumsum(response) pylab.stem(x, step) pylab.ylabel('Amplitude') pylab.xlabel(r'n (samples)') pylab.title(r'Step response') pylab.subplots_adjust(hspace=0.5)
def impz(b, a=1): ''' #Plot step and impulse response from http://mpastell.com/2010/01/18/fir-with-scipy/ ''' l = len(b) impulse = pylab.repeat(0., l) impulse[0] = 1. x = numpy.arange(0, l) response = signal.lfilter(b, a, impulse) pylab.subplot(211) pylab.stem(x, response) pylab.ylabel('Amplitude') pylab.xlabel(r'n (samples)') pylab.title(r'Impulse response') pylab.subplot(212) step = numpy.cumsum(response) pylab.stem(x, step) pylab.ylabel('Amplitude') pylab.xlabel(r'n (samples)') pylab.title(r'Step response') pylab.subplots_adjust(hspace=0.5)
def print_QE_tables(Qs,Es,qs,delim="\t"): """ Returns string of 'delim'-delimited printout. Assumes that Qs,Es are of the form returned by the Stats.QEPlot method, and that qs is the list of quantile percentages that were supplied to the same method. """ ret = "" rows = array(Qs.keys()) rows.sort() # we want 3 values for each Q and also the E qs = map(str,repeat(qs,3)) for i in range(len(qs)/3): qs[i*3+0] += " lower CI" qs[i*3+1] += " upper CI" cols = qs+["E","E-moe","E+moe"] ret += delim + delim.join(cols) + "\n" for row in rows: Q = Qs[row] E,moe = Es[row] ret += str(row) + delim for qlh in Q: #excel wants low,high,middle ret += delim.join(map(str,(qlh[1],qlh[2],qlh[0]))) + delim ret += str(E) + delim + str(E-moe) + delim + str(E+moe) ret += "\n" return ret
def print_QE_tables(Qs, Es, qs, delim="\t"): """ Returns string of 'delim'-delimited printout. Assumes that Qs,Es are of the form returned by the Stats.QEPlot method, and that qs is the list of quantile percentages that were supplied to the same method. """ ret = "" rows = array(Qs.keys()) rows.sort() # we want 3 values for each Q and also the E qs = map(str, repeat(qs, 3)) for i in range(len(qs) / 3): qs[i * 3 + 0] += " lower CI" qs[i * 3 + 1] += " upper CI" cols = qs + ["E", "E-moe", "E+moe"] ret += delim + delim.join(cols) + "\n" for row in rows: Q = Qs[row] E, moe = Es[row] ret += str(row) + delim for qlh in Q: #excel wants low,high,middle ret += delim.join(map(str, (qlh[1], qlh[2], qlh[0]))) + delim ret += str(E) + delim + str(E - moe) + delim + str(E + moe) ret += "\n" return ret
# keep only lowest level of each selected branch nz = len(zelong) keep = pl.ones(nz, dtype=bool) for i in range(nz): if keep[i]: t = d[zelong[i]] for k in t.descendants: if k.idx in zelong: keep[i] = False zelong = zelong[keep] n_elong_dendro = len(zelong) # this will be for the list of fil,branch pairs that overlap this dendro, and by how many pixels: overlapping_fil_branches = pl.repeat({}, n_elong_dendro) for i in range(n_elong_dendro): overlapping_fil_branches[i] = { "dendro_id": 0, "filbranches": [], "npixoverlap": [] }.copy() #================================================================ mom8 = fits.getdata(mom8file) pl.clf() pl.imshow((pl.nanmax(mom8) - mom8), origin="bottom", cmap="gray") pl.subplots_adjust(left=0.05, right=0.98, bottom=0.05, top=0.98) pl.xlim(xra) pl.ylim(yra)