def h_field(a, b, m, n, omega, lambda_mn, x_min, x_max, dx, y_min, y_max, dy, z_min, z_max, dz, t_min, t_max, t_step): for t in drange(t_min, t_max, t_step): for z in drange(z_min, z_max, dz): for y in drange(y_min, y_max, dy): for x in drange(x_min, x_max, dx): vector_dx = hx(a, b, m, n, omega, lambda_mn, x, y, z, t) vector_dy = hy(a, b, m, n, omega, lambda_mn, x, y, z, t) vector_dz = hz(a, b, m, n, omega, lambda_mn, x, y, z, t) yield gplot_vector3(x, y, z, vector_dx, vector_dy, vector_dz) # Returning None to specify the end of one time frame yield None
import math as m from mk_galaxy_struc import mk_galaxy_struc from drange import drange sample = [] # get galaxy info galaxies = mk_galaxy_struc() for i in range(len(galaxies)): if galaxies[i].ston_I > 30.0 and galaxies[i].ICD_IH <= 0.25: sample.append([galaxies[i].ICD_IH, galaxies[i].Mass]) sample = np.asarray(sample) # make the bins bins = [] for i in drange(7.0, 12.5, 0.1): bins.append(10.0 ** i) bins = np.asarray(bins) # digitize the sample inds = np.digitize(sample[:, 1], bins) # put the sample in the postboxes sorted = [] for i in range(bins.size): sorted.append([]) for i in range(inds.size): j = int(inds[i]) sorted[j].append(i) # match the sample to the icd's
def plot_histogram(xs, filename, title, xlabel, lower, upper, normed=False): old_lower, old_upper = int(lower * 1000), int(upper * 1000) # lower/upper is in percentage. # in order to see what's appropriate, we need to figure out the scale. # like this? # http://stackoverflow.com/questions/15177203/how-is-the-pyplot-histogram-bins-interpreted matching_xs = [x for x in xs if x >= lower and x <= upper] if len(matching_xs) == 0: print "Nothing matching for", lower, upper return """ if lower == 75: i = 0 for x in matching_xs: print x, if i % 80 == 0: print i+=1 #matching_xs = [99]*20 + [90]*10 + [80]*5 pass """ # at least MIN_RANGE steps. step = upper - lower if step < MIN_RANGE: step = float(step) / MIN_RANGE else: step = 1.0 bins = [i for i in drange(lower, upper + 0.000001, step)] #print "bins from lower to upper:", bins #n, bins, patches = plt.hist(matching_xs, bins=[0, 70,80,90,100], histtype='stepfilled') #n, bins, patches = plt.hist(xs, bins=100, range=(lower, upper), histtype='stepfilled') #n, bins, patches = plt.hist(xs, bins=100, histtype='stepfilled') #n, bins, patches = plt.hist(matching_xs, bins=100, histtype='stepfilled') n, bins, patches = plt.hist(matching_xs, bins=bins, normed=normed, histtype='stepfilled') #n, bins, patches = plt.hist(matching_xs, bins=bins, histtype='stepfilled') #print "n =", n print "lower, upper =", lower, upper #print "bins =", bins #print "patches =", patches plt.xlabel(xlabel) plt.ylabel("Handle count / % of max") plt.title("Histogram of memory area lifetime (%d - %d): %s" % (old_lower, old_upper, title)) #plt.axis([100, 0, 0, len(bins)*0.75]) plt.axis('tight') plt.grid(True) ax = plt.gca() ax.xaxis.set_major_formatter( mpl.ticker.FuncFormatter(formatter_x_to_percent)) ymin, ymax = ax.get_ylim() ax.yaxis.set_major_formatter( mpl.ticker.FuncFormatter( lambda y, pos: formatter_max_to_percent(y, pos, ymax))) #plt.show() fname = "%s-histogram-%d-%d.pdf" % (filename, old_lower, old_upper) plt.savefig(fname) print "Saved histogram:", fname plt.clf() plt.cla() plt.close()
def plot_histogram(xs, filename, title, xlabel, lower, upper, normed=False): old_lower, old_upper = int(lower*1000), int(upper*1000) # lower/upper is in percentage. # in order to see what's appropriate, we need to figure out the scale. # like this? # http://stackoverflow.com/questions/15177203/how-is-the-pyplot-histogram-bins-interpreted matching_xs = [x for x in xs if x >= lower and x <= upper] if len(matching_xs) == 0: print "Nothing matching for", lower, upper return """ if lower == 75: i = 0 for x in matching_xs: print x, if i % 80 == 0: print i+=1 #matching_xs = [99]*20 + [90]*10 + [80]*5 pass """ # at least MIN_RANGE steps. step = upper-lower if step < MIN_RANGE: step = float(step) / MIN_RANGE else: step = 1.0 bins = [i for i in drange(lower, upper+0.000001, step)] #print "bins from lower to upper:", bins #n, bins, patches = plt.hist(matching_xs, bins=[0, 70,80,90,100], histtype='stepfilled') #n, bins, patches = plt.hist(xs, bins=100, range=(lower, upper), histtype='stepfilled') #n, bins, patches = plt.hist(xs, bins=100, histtype='stepfilled') #n, bins, patches = plt.hist(matching_xs, bins=100, histtype='stepfilled') n, bins, patches = plt.hist(matching_xs, bins=bins, normed=normed, histtype='stepfilled') #n, bins, patches = plt.hist(matching_xs, bins=bins, histtype='stepfilled') #print "n =", n print "lower, upper =", lower, upper #print "bins =", bins #print "patches =", patches plt.xlabel(xlabel) plt.ylabel("Handle count / % of max") plt.title("Histogram of memory area lifetime (%d - %d): %s" % (old_lower, old_upper, title)) #plt.axis([100, 0, 0, len(bins)*0.75]) plt.axis('tight') plt.grid(True) ax = plt.gca() ax.xaxis.set_major_formatter(mpl.ticker.FuncFormatter(formatter_x_to_percent)) ymin, ymax = ax.get_ylim() ax.yaxis.set_major_formatter(mpl.ticker.FuncFormatter(lambda y, pos: formatter_max_to_percent(y, pos, ymax))) #plt.show() fname = "%s-histogram-%d-%d.pdf" % (filename, old_lower, old_upper) plt.savefig(fname) print "Saved histogram:", fname plt.clf() plt.cla() plt.close()
import math as m from mk_galaxy_struc import mk_galaxy_struc from drange import drange sample = [] # get galaxy info galaxies = mk_galaxy_struc() for i in range(len(galaxies)): if galaxies[i].ston_I > 30.0 and galaxies[i].ICD_IH <= 0.25: sample.append([galaxies[i].ICD_IH,galaxies[i].Mass]) sample = np.asarray(sample) # make the bins bins = [] for i in drange(7.0,12.5,0.1): bins.append(10.0**i) bins = np.asarray(bins) # digitize the sample inds = np.digitize(sample[:,1],bins) # put the sample in the postboxes sorted =[] for i in range(bins.size): sorted.append([]) for i in range(inds.size): j = int(inds[i]) sorted[j].append(i) # match the sample to the icd's