rootpy.plotting.Hist

class rootpy.plotting.Hist(*args, **kwargs)[source]

Returns a 1-dimensional Hist object which inherits from the associated ROOT.TH1* class (where * is C, S, I, F, or D depending on the type keyword argument)

Draw(*args, **kwargs)
Parameters:

args : positional arguments

Positional arguments are passed directly to ROOT’s Draw

kwargs : keyword arguments

If keyword arguments are present, then a clone is drawn instead with DrawCopy, where the name, title, and style attributes are taken from kwargs.

Returns:

If kwargs is not empty and a clone is drawn, then the clone is

returned, otherwise None is returned.

DrawCopy(*args, **kwargs)
Parameters:

args : positional arguments

Positional arguments are passed directly to ROOT’s Draw

kwargs : keyword arguments

The name, title, and style attributes of the clone are taken from kwargs.

Returns:

The clone.

GetFillColor(mode=None)

mode may be ‘root’, ‘mpl’, or None to return the ROOT, matplotlib, or input value.

GetFillStyle(mode=None)

mode may be ‘root’, ‘mpl’, or None to return the ROOT, matplotlib, or input value.

GetLineColor(mode=None)

mode may be ‘root’, ‘mpl’, or None to return the ROOT, matplotlib, or input value.

GetLineStyle(mode=None)

mode may be ‘root’, ‘mpl’, or None to return the ROOT, matplotlib, or input value.

GetMarkerColor(mode=None)

mode may be ‘root’, ‘mpl’, or None to return the ROOT, matplotlib, or input value.

GetMarkerStyle(mode=None)

mode may be ‘root’, ‘mpl’, or None to return the ROOT, matplotlib, or input value.

SetColor(color)

color may be any color understood by ROOT or matplotlib.

Set all color attributes with one method call.

For full documentation of accepted color arguments, see rootpy.plotting.style.Color.

SetFillColor(color)

color may be any color understood by ROOT or matplotlib.

For full documentation of accepted color arguments, see rootpy.plotting.style.Color.

SetFillStyle(style)

style may be any fill style understood by ROOT or matplotlib.

For full documentation of accepted style arguments, see rootpy.plotting.style.FillStyle.

SetLineColor(color)

color may be any color understood by ROOT or matplotlib.

For full documentation of accepted color arguments, see rootpy.plotting.style.Color.

SetLineStyle(style)

style may be any line style understood by ROOT or matplotlib.

For full documentation of accepted style arguments, see rootpy.plotting.style.LineStyle.

SetMarkerColor(color)

color may be any color understood by ROOT or matplotlib.

For full documentation of accepted color arguments, see rootpy.plotting.style.Color.

SetMarkerStyle(style)

style may be any marker style understood by ROOT or matplotlib.

For full documentation of accepted style arguments, see rootpy.plotting.style.MarkerStyle.

bins_range(axis=0, overflow=False)

Return a range of bin indices for iterating along an axis

Parameters:

axis : int, optional (default=1)

The axis (0, 1 or 2).

overflow : bool, optional (default=False)

If True then include the underflow and overflow bins otherwise only include the visible bins.

Returns:

an range object of bin indices

bounds(axis=0)

Get the lower and upper bounds of the binning along an axis

check_compatibility(other, check_edges=False, precision=1e-07)

Test whether two histograms are considered compatible by the number of dimensions, number of bins along each axis, and optionally the bin edges.

Parameters:

other : histogram

A rootpy histogram

check_edges : bool, optional (default=False)

If True then also check that the bin edges are equal within the specified precision.

precision : float, optional (default=1E-7)

The value below which differences between floats are treated as nil when comparing bin edges.

Raises:

TypeError

If the histogram dimensionalities do not match

ValueError

If the histogram sizes, number of bins along an axis, or optionally the bin edges do not match

decorate(other=None, **kwargs)

Apply style options to a Plottable object.

Returns a reference to self.

empty_clone(binning=None, axis=0, type=None, **kwargs)

Return a new empty histogram. The binning may be modified along one axis by specifying the binning and axis arguments. If binning is False, then the corresponding axis is dropped from the returned histogram.

fill_array(array, weights=None)

Fill this histogram with a NumPy array

fill_view(view)

Fill this histogram from a view of another histogram

get_sum_w2(ix, iy=0, iz=0)

Obtain the true number of entries in the bin weighted by w^2

integral(xbin1=None, xbin2=None, width=False, error=False, overflow=False)

Compute the integral and error over a range of bins

lowerbound(axis=0)

Get the lower bound of the binning along an axis

merge_bins(bin_ranges, axis=0)

Merge bins in bin ranges

Parameters:

bin_ranges : list of tuples

A list of tuples of bin indices for each bin range to be merged into one bin.

axis : int (default=1)

The integer identifying the axis to merge bins along.

Returns:

hist : TH1

The rebinned histogram.

Examples

Merge the overflow bins into the first and last real bins:

newhist = hist.merge_bins([(0, 1), (-2, -1)])
nbins(axis=0, overflow=False)

Get the number of bins along an axis

overflow(axis=0)

Return the overflow for the given axis.

Depending on the dimension of the histogram, may return an array.

poisson_errors()

Return a TGraphAsymmErrors representation of this histogram where the point y errors are Poisson.

quantiles(quantiles, axis=0, strict=False, recompute_integral=False)

Calculate the quantiles of this histogram.

Parameters:

quantiles : list or int

A list of cumulative probabilities or an integer used to determine equally spaced values between 0 and 1 (inclusive).

axis : int, optional (default=0)

The axis to compute the quantiles along. 2D and 3D histograms are first projected along the desired axis before computing the quantiles.

strict : bool, optional (default=False)

If True, then return the sorted unique quantiles corresponding exactly to bin edges of this histogram.

recompute_integral : bool, optional (default=False)

If this histogram was filled with SetBinContent instead of Fill, then the integral must be computed before calculating the quantiles.

Returns:

output : list or numpy array

If NumPy is importable then an array of the quantiles is returned, otherwise a list is returned.

rebinned(bins, axis=0)

Return a new rebinned histogram

Parameters:

bins : int, tuple, or iterable

If bins is an int, then return a histogram that is rebinned by grouping N=``bins`` bins together along the axis axis. If bins is a tuple, then it must contain the same number of elements as there are dimensions of this histogram and each element will be used to rebin along the associated axis. If bins is another iterable, then it will define the bin edges along the axis axis in the new rebinned histogram.

axis : int, optional (default=0)

The axis to rebin along.

Returns:

The rebinned histogram

set_sum_w2(w, ix, iy=0, iz=0)

Sets the true number of entries in the bin weighted by w^2

smoothed(iterations=1)

Return a smoothed copy of this histogram

Parameters:

iterations : int, optional (default=1)

The number of smoothing iterations

Returns:

hist : asrootpy’d histogram

The smoothed histogram

underflow(axis=0)

Return the underflow for the given axis.

Depending on the dimension of the histogram, may return an array.

uniform(axis=None, precision=1e-07)

Return True if the binning is uniform along the specified axis. If axis is None (the default), then return True if the binning is uniform along all axes. Otherwise return False.

Parameters:

axis : int (default=None)

Axis along which to check if the binning is uniform. If None, then check all axes.

precision : float (default=1E-7)

The threshold below which differences in bin widths are ignored and treated as equal.

Returns:

True if the binning is uniform, otherwise False.

uniform_binned(name=None)

Return a new histogram with constant width bins along all axes by using the bin indices as the bin edges of the new histogram.

upperbound(axis=0)

Get the upper bound of the binning along an axis

xyz(idx)

return binx, biny, binz corresponding to the global bin number