def plot_counts(values, ax=None, xscale='lin', yscale='lin', xParam=None, label=None, **kwargs): """ Plots the probability density function of given values. Parameters ---------- values : numpy ndarray the values for which the experimental pdf is computed ax : matplotlib axes object, optional axes to plot the figure in xscale : str 'lin' or 'log', or ... (see binner.Bins for more details) yscale : str 'lin' or 'log' xParam : different things, optional see binner.Bins for more details **kwargs : kwargs keyword arguments that will be passed to matplotlib hist function Returns ------- fig : matplotlib Figure the parent figure of the axes ax : matplotlib Axes object the axes in which the pdf is plotted """ if ax is None: fig = plt.figure() ax = fig.add_subplot(111) else: fig = ax.get_figure() indices = bins.get_reasonable_data_indices_for_binning(values, xscale=xscale) prop_vals = values[indices] if xParam is None: if xscale == 'log': xParam = np.sqrt(2) # just getting a nice factor of two... if xscale == 'lin': xParam = 50 xbins = bins.Bins(float, np.min(prop_vals), np.max(prop_vals), xscale, xParam) ax.hist(values, bins=xbins.bin_limits, normed=False, label=label, **kwargs) if 'log' in xscale: ax.set_xscale('log') if 'log' in yscale: ax.set_yscale('log') return fig, ax
def plot_counts(values, ax=None, xscale='lin', yscale='lin', xParam=None, label=None, **kwargs): """ Plots the probability density function of given values. Parameters ---------- values : numpy ndarray the values for which the experimental pdf is computed ax : matplotlib axes object, optional axes to plot the figure in xscale : str 'lin' or 'log', or ... (see binner.Bins for more details) yscale : str 'lin' or 'log' xParam : different things, optional see binner.Bins for more details **kwargs : kwargs keyword arguments that will be passed to matplotlib hist function Returns ------- fig : matplotlib Figure the parent figure of the axes ax : matplotlib Axes object the axes in which the pdf is plotted """ if ax is None: fig = plt.figure() ax = fig.add_subplot(111) else: fig = ax.get_figure() indices = bins.get_reasonable_data_indices_for_binning( values, xscale=xscale) prop_vals = values[indices] if xParam is None: if xscale == 'log': xParam = np.sqrt(2) # just getting a nice factor of two... if xscale == 'lin': xParam = 50 xbins = bins.Bins(float, np.min(prop_vals), np.max(prop_vals), xscale, xParam) ax.hist(values, bins=xbins.bin_limits, normed=False, label=label, **kwargs) if 'log' in xscale: ax.set_xscale('log') if 'log' in yscale: ax.set_yscale('log') return fig, ax
def _get_count_data_to_plot(x, y, xscale, yscale, xParam, yParam): """ See e.g. function plot_counts for interpreting the inner workings of this function. """ if type(x) is not np.ndarray: x = np.array(x) if type(y) is not np.ndarray: y = np.array(y) xidx, yidx = bins.get_reasonable_data_indices_for_binning( x, y, xscale, yscale) min_x, max_x = min(x[xidx]), max(x[xidx]) min_y, max_y = min(y[yidx]), max(y[yidx]) bins2D = bins.Bins2D( float, min_x, max_x, xscale, xParam, float, min_y, max_y, yscale, yParam ) counts_matrix, _, _ = np.histogram2d( x, y, bins=bins2D.bin_limits) # counts_matrix = counts_matrix.astype(np.float64) counts_matrix = counts_matrix.T counts_matrix = np.ma.masked_array(counts_matrix, counts_matrix == 0) X, Y = bins2D.edge_grids # compute bin average as a function of x: x_bin_means, _, _ = scipy.stats.binned_statistic( x, x, statistic='mean', bins=bins2D.xbin_lims ) y_bin_means, _, _ = scipy.stats.binned_statistic( x, y, statistic='mean', bins=bins2D.xbin_lims ) return X, Y, counts_matrix, x_bin_means, y_bin_means, bins2D
def _get_count_data_to_plot(x, y, xscale, yscale, xParam, yParam): """ See e.g. function plot_counts for interpreting the inner workings of this function. """ if type(x) is not np.ndarray: x = np.array(x) if type(y) is not np.ndarray: y = np.array(y) xidx, yidx = bins.get_reasonable_data_indices_for_binning( x, y, xscale, yscale) min_x, max_x = min(x[xidx]), max(x[xidx]) min_y, max_y = min(y[yidx]), max(y[yidx]) bins2D = bins.Bins2D(float, min_x, max_x, xscale, xParam, float, min_y, max_y, yscale, yParam) counts_matrix, _, _ = np.histogram2d(x, y, bins=bins2D.bin_limits) # counts_matrix = counts_matrix.astype(np.float64) counts_matrix = counts_matrix.T counts_matrix = np.ma.masked_array(counts_matrix, counts_matrix == 0) X, Y = bins2D.edge_grids # compute bin average as a function of x: x_bin_means, _, _ = scipy.stats.binned_statistic(x, x, statistic='mean', bins=bins2D.xbin_lims) y_bin_means, _, _ = scipy.stats.binned_statistic(x, y, statistic='mean', bins=bins2D.xbin_lims) return X, Y, counts_matrix, x_bin_means, y_bin_means, bins2D