def densityPlot(x, y, bins2D=None, bins=None, xscale='log', yscale='log', nbinsX=1.5, nbinsY=1.5, weights=None): """ 2-Plot static distance vs temporal distance Plot fraction of Finite distances vs temporal distance Plot the distance distribution """ x = np.array(x) y = np.array(y) if bins2D == None or bins == None: xidx, yidx = getLimits2D(x, y, xscale, yscale) minValueX, maxValueX = min(x[xidx]), max(x[xidx]) minValueY, maxValueY = min(y[yidx]), max(y[yidx]) print minValueX, maxValueX, minValueY, maxValueY bins2D = binner.Bins2D(float, minValueX, maxValueX, xscale, nbinsX, float, minValueY, maxValueY, yscale, nbinsY) bins = binner.Bins(float, minValueX, maxValueX, xscale, nbinsX) binned_data, b1, b2 = np.histogram2d(x, y, bins=bins2D.bin_limits, weights=weights) binned_data = binned_data.astype(np.float64) X, Y = bins2D.edge_grids z, b = np.histogram(x, bins=bins.bin_limits, weights=weights) for i in np.nonzero(z)[0]: binned_data[i, :] = binned_data[i, :] / z[i] binned_data = binned_data.transpose() binned_data = np.ma.masked_array(binned_data, binned_data == 0) if weights == None: z1, b = np.histogram(x, bins=bins.bin_limits, weights=y) else: z1, b = np.histogram(x, bins=bins.bin_limits, weights=y * weights) z1 = z1.astype(np.float64) for i in np.nonzero(z)[0]: z1[i] = z1[i] / z[i] return X, Y, binned_data, bins, z1
def setUp(self): self.x_coords = [1, 1, 2, 4, 4, 3, 1, 2] self.y_coords = [1, 4, 3, 5, 6, 1, 8, 6] values = [1, 3, 7, 5, 6, 3, 1, 10] weights = [1, 3, 1, 0, 100, 0, 1, 10] self.coords = zip(self.x_coords, self.y_coords) self.data = zip(self.x_coords, self.y_coords, values) self.weighted_data = zip(self.x_coords, self.y_coords, values, weights) bad_x_coords = [1, 1, 2, 4, 4, 5, 1, 2] bad_y_coords = [1, 4, 0, 5, 6, 1, 8, 6] self.bad_coords_A = zip(bad_x_coords, self.y_coords) self.bad_coords_B = zip(self.x_coords, bad_y_coords) self.bad_data_A = zip(bad_x_coords, self.y_coords, values) self.bad_data_B = zip(self.x_coords, bad_y_coords, values) self.bad_wdata_A = zip(bad_x_coords, self.y_coords, values, weights) self.bad_wdata_B = zip(self.x_coords, bad_y_coords, values, weights) self.bins = binner.Bins2D(int, 0, 0, 'custom', [1, 1.5, 4], int, 0, 0, 'custom', [1, 4.5, 5.5, 6.5, 10])