Data Visualization (skhep.visual)

class skhep.visual.MplPlotter(show_backend=False)
static hist(x, bins='auto', range=None, weights=None, errorbars=False, normed=False, scale=None, stacked=False, histtype='stepfilled', **kwargs)

Enhanced histogram, based on hist function from matplotlib and astroML. The main additional features are the ability to use data-driven binning algorithms, the addition of errorbars, scaling options (like dividing all bin values by their widths), and marker-style draw options. hist function wraps HistContainer class, which does the majority of work.

Parameters:
  • x (array, or list of array) – Array of data to be histogrammed.
  • bins (int or List or str, optional) –

    If int, bins number of equal-width bins are generated. The width is determined by either equal divison of the given range, or equal division between the first and last data point if no range is specified.

    If List, bin edges are taken directly from List (can be unequal width).

    If str, then it must be one of:

    'blocks' : use bayesian blocks for dynamic bin widths.
    
    'auto' : use 'auto' feature from numpy.histogram.
    

    Defaults to ‘auto’.

  • range (tuple or None, optional) –

    If specificed, data will only be considered and shown for the range given. Otherwise, range will be between the highest and lowest datapoint.

    Defaults to None.

  • weights (array or None, optional) –

    Weights associated with each data point. If specified, bin content will be equal to the sum of all relevant weights.

    Defaults to None.

  • errorbars (boolean or array, optional) –

    If True, errorbars will be calculated and displayed based on the err_* arguments. The errorbars will be appropriately modified if scale and/or normed is True. If an array is specificed, those values will be used (and will not be modifed by any other methods).

    Defaults to False.

  • normed (boolean, optional) –

    If True, histogram will be normalized such that the integral over all bins with be equal to 1. In general, this will NOT mean that the sum of all bin contents will be 1, unless all bin widths are equal to 1. If used with scale option, normalization happens before scale.

    Defaults to False

  • scale (Number or 'binwidth', optional) –

    If Number, all bin contents are multiplied by the given value. If ‘binwidth’, every bin content is divided by the bin width. If used with normed option, scaling occurs after normalization (‘binwidth’ will be ignored in this case, because it is handled automatically when normalizing).

    Defaults to None

  • stacked (boolean, optional) –

    If True, multiple input data sets will be layered on top of each other, such that the height of each bin is the sum of all the relevant dataset contributions. If used with errorbars, the bars will be associated with the bin totals, not the individual components.

    Defaults to False.

  • histtype (stepfilled', 'step', 'bar', or 'marker') –

    Draw options for histograms. ‘stepfilled’, ‘step’, and ‘bar’ inherit from matplotlib. ‘marker’ places a single point at the center of each bin (best used with error bars). ‘marker’ will throw an exception if used with ‘stacked’ option.

    Defaults to ‘stepfilled’.

  • **kwargs
    • ax (matplotlib axes instance):
      Specify the Axes on which to draw the histogram. If not specified, then the current active axes will be used, or a new axes instance will be generated.

      Defaults to current axis.

    • err_style (‘band’ or ‘line’):
      Draw style for errorbars.

      Defaults depend on histtype, where histtype=’stepfilled’ corresponds to ‘band’, and all others correspond to ‘line’.

    • err_color (‘auto’ or valid matplotlib colors):
      Color for error bars. If ‘auto’ is chosen and stacked is False, The color will be a slightly darker version of the associated histogram color. If stacked is True, color will be the next in the current color cycle.

      Defaults to ‘auto’.

    • err_type (‘sumW2’ or ‘gaussian’):
      Method of calculating error bars, if no error is given. The ‘gaussian’ method displays the error of each bin as the square root of the bin content. The ‘sumW2’ method displays the error as the square of the sum of the squares of the weights.

      Defaults to ‘gaussian’ if no weights are given, else ‘sumW2’.

    • err_return (bool):
      Return additional objects corresponding to the values of the error associated with each bin, and the patches used to display the error bars.

      Defaults to ‘False’

  • Note – Other keyword arguments are described in pylab.hist().
Returns:

(bin_content, bin_edges, bin_errors (optional), patches)

bin_content (array or list of array):

The values of the histogram bins. See normed or density and weights for a description of the possible semantics. If input x is an array, then this is an array of length nbins. If input is a sequence arrays [data1, data2,..], then this is a list of arrays with the values of the histograms for each of the arrays in the same order.

bin_edges (array):

The edges of the bins. Length nbins + 1 (nbins left edges and right edge of last bin). Always a single array even when multiple data sets are passed in.

bin_errors (array or list of arrays, optional):

The values of the error bars associated with each bin. It is only returned if errorbars is True and err_return is True.

bin_patches (list or list of lists):

Silent list of individual patches used to create the histogram or list of such list if multiple input datasets.

Brian Pollack, 2017

static ratio_plot(hist_dict1, hist_dict2, bins=None, range=None, ratio_range=None, err_style='band', err_color='dimgray', ratio_mode='default', grid=False, unity_line='red', logx=False)

Function for creating ratio plots (comparing two histograms by dividing their bin content). The call structure is very similar to producing two individual histograms, with additional arguments specifying the nature of the ratio plot. The number of bins and ranges for both histograms must be equal.

Note

Addition documentation soon.