Axis
- class histpy.Axis(edges, label=None, scale=None, unit=None, copy=True)[source]
Bases:
objectBin edges. Optionally labeled
You can select specific edges using the slice operator (
[]). The result is also another Axis object.- Parameters:
edges (array-like) – Bin edges. Can be a Quantity array, if you need units
label (str) – Label for axis. If edges is an Axis object, this will override its label
scale (str) – Bin center mode e.g. “linear” or “log”. See axis_scale property. If edges is an Axis object, this will override its mode
unit (unit-like) – Unit for axis (will override unit of edges)
copy (bool) – True if edge array should be distinct from passed-in edges; if False, will use same edge array if possible
- property unit
Return the astropy units of the axis. Or
Noneis units where not declare.
- to(unit, equivalencies=[], update=True, copy=True)[source]
Convert an Axis to a different unit.
- Parameters:
unit (unit-like) – Unit to convert to.
equivalencies (list or tuple) – A list of equivalence pairs to try if the units are not directly convertible.
update (bool) – If
updateisFalse, only the units will be changed without updating the edges accordinglycopy (bool) – If True (default), then the value is copied. Otherwise, a copy will only be made if necessary.
- property axis_scale
Control what is considered the center of the bin. This affects centers() and interpolation.
- Modes:
linear (default): The center is the midpoint between the bin edges
symmetric: same as linear, except for the first center, which will correspond to the lower edge. This is, for example, useful when the histogram is filled with the absolute value of a variable.
log: The center is the logarithmic (or geometrical) midpoint between the bin edges.
- find_bin(value, right=False)[source]
Return the bin value corresponds to.
- Parameters:
value – scalar or np.ndarray value(s) to bin
right – bool If false, a bin strictly includes its left edge If true, a bin strictly includes its right edge
- Returns:
Bin number. -1 for underflow, nbins for overflow
- Return type:
int
- interp_weights(values)[source]
Get the two closest bins to each value in values, together with the weights to linearly interpolate between the centers of these two bins.
If the axis has log scale, interpolation weights are computed in the log domain, and values must be > 0.
Before interpolation, values are be clamped to be at least the center of the first bin and at most the center of the last bin.
- Returns:
int array containing left and right bins for each value, of shape
(2,) if values is scalar or 0-D array, (2, values.shape) otherwise
Weights: float array containing left and right weights for each value, of shape
(2,) if values is scalar or 0-D array, (2, values.shape) otherwise
- Return type:
Bins
NB: return values are for compatibility with old code; it would suffice to return bins[0] and weights[0], since bins[1] = bins[0] + 1 and weights[1] = 1. - weights[0].
- property lower_bounds
Lower bound of each bin
- property upper_bounds
Upper bound of each bin
- property bounds
Start of [lower_bound, upper_bound] values for each bin.
- property lo_lim
Overall lower bound
- property hi_lim
Overall upper bound of histogram
- property edges
Edges of each bin
- property label
Axis label
- property label_with_unit
Axis ‘label [units]’
- property centers
Center of each bin, in linear domain and axis units, if any
- property widths
Width of each bin.
- property nbins
Number of elements along each axis. Either an int (1D histogram) or an array