hist.plot module#
- hist.plot.hist2dplot(H, xbins=None, ybins=None, labels=None, labels_fontsize=None, labels_round=None, labels_color=None, cbar: bool = True, cbarsize='7%', cbarpad=0.2, cbarpos='right', cbarextend=None, cmin=None, cmax=None, mask=None, ax: Axes | None = None, flow='hint', binwnorm=None, **kwargs)#
Create a 2D histogram plot from np.histogram-like inputs.
- Parameters:
H (object) –
Histogram object with containing values and optionally bins. Can be:
np.histogram tuple
boost_histogram histogram object
raw histogram values as list of list or 2d-array
xbins (1D array-like, optional, default None) – Histogram bins along x axis, if not part of
H.ybins (1D array-like, optional, default None) – Histogram bins along y axis, if not part of
H.labels (2D array (H-like) or bool, default None, optional) – Array of per-bin labels to display. If
Truewill display numerical valueslabels_fontsize (float, optional, default None) – Fontsize of labels.
labels_color (str, optional, default None) – Color of labels. If not given, will be decided automatically.
labels_round (int, optional, default None) – Round labels to given number of decimals
cbar (bool, optional, default True) – Draw a colorbar. In contrast to mpl behaviors the cbar axes is appended in such a way that it doesn’t modify the original axes width:height ratio.
cbarsize (str or float, optional, default "7%") – Colorbar width.
cbarpad (float, optional, default 0.2) – Colorbar distance from main axis.
cbarpos ({'right', 'left', 'bottom', 'top'}, optional, default "right") – Colorbar position w.r.t main axis.
cbarextend (bool, optional, default None (auto)) – Extends figure size to keep original axes size same as without cbar. If None (default), automatically set to True for single-axes figures and False for multi-axes figures to prevent layout issues.
cmin (float, optional) – Colorbar minimum.
cmax (float, optional) – Colorbar maximum.
mask (2D array (H-like), optional) – Boolean mask to hide cells. Cells with False value are not shown.
ax (matplotlib.axes.Axes, optional) – Axes object (if None, last one is fetched or one is created)
flow (str, optional {"show", "sum","hint", None}) – Whether plot the under/overflow bin. If “show”, add additional under/overflow bin. If “sum”, add the under/overflow bin content to first/last bin. “hint” would highlight the bins with under/overflow contents
binwnorm (float, optional) –
- If true, convert sum weights to bin-width-normalized, with unit equal to
supplied value (usually you want to specify 1.)
**kwargs – Keyword arguments passed to underlying matplotlib function - pcolormesh.
- Return type:
Hist2DArtist
- hist.plot.histplot(H, bins=None, *, yerr: ArrayLike | bool | None = None, w2=None, w2method=None, stack: bool = False, density: bool = False, binwnorm=None, histtype: str = 'step', xerr=False, label=None, sort=None, edges=True, binticks=False, xoffsets=None, ax: mpl.axes.Axes | None = None, flow='hint', **kwargs)#
Create a 1D histogram plot from np.histogram-like inputs.
- Parameters:
H (object) –
Histogram object with containing values and optionally bins. Can be:
np.histogram tuple
PlottableProtocol histogram object
boost_histogram classic (<0.13) histogram object
raw histogram values, provided bins is specified.
Or list thereof.
bins (iterable, optional) – Histogram bins, if not part of
H.yerr (iterable or bool, optional) – Histogram uncertainties. Following modes are supported: - True, sqrt(N) errors or poissonian interval when
w2is specified - shape(N) array of for one sided errors or list thereof - shape(Nx2) array of for two sided errors or list thereofw2method (callable, optional) – Function calculating CLs with signature
low, high = fcn(w, w2). Herelowandhighare given in absolute terms, not relative to w. Default isNone. If w2 has integer values (likely to be data) poisson interval is calculated, otherwise the resulting error is symmetricsqrt(w2). Specifyingpoissonorsqrtwill force that behaviours.stack (bool, optional) – Whether to stack or overlay non-axis dimension (if it exists). N.B. in contrast to ROOT, stacking is performed in a single call aka
histplot([h1, h2, ...], stack=True)as opposed to multiple calls.density (bool, optional) – If true, convert sum weights to probability density (i.e. integrates to 1 over domain of axis) (Note: this option conflicts with
binwnorm)binwnorm (float, optional) –
- If true, convert sum weights to bin-width-normalized, with unit equal to
supplied value (usually you want to specify 1.)
histtype ({'step', 'fill', 'errorbar', 'bar', 'barstep', 'band'}, optional, default: "step") –
Type of histogram to plot:
”step”: skyline/step/outline of a histogram using [plt.stairs](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.stairs.html#matplotlib-axes-axes-stairs).
”fill”: filled histogram using [plt.stairs](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.stairs.html#matplotlib-axes-axes-stairs).
”errorbar”: single marker histogram using [plt.errorbar](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.errorbar.html#matplotlib-axes-axes-errorbar).
”bar”: If multiple data are given the bars are arranged side by side using [plt.bar](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.bar.html#matplotlib-axes-axes-bar). If only one histogram is provided, it will be treated as “fill” histtype.
”barstep”: If multiple data are given the steps are arranged side by side using [plt.stairs](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.stairs.html#matplotlib-axes-axes-stairs). Supports yerr representation. If one histogram is provided, it will be treated as “step” histtype.
”band”: filled band spanning the yerr range of the histogram using [plt.stairs](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.stairs.html#matplotlib-axes-axes-stairs).
sort (str, optional {'label'/'l', 'yield'/'y'}) – “label”/”l”: sort histograms alphabetically by label, “yield”/”y”: sort by total histogram yield. Append ‘_r’ to reverse the order.
ax (matplotlib.axes.Axes, optional) – Axes object (if None, last one is fetched or one is created)
flow (str, optional { "show", "sum", "hint", "none"}) – Whether plot the under/overflow bin. If “show”, add additional under/overflow bin. If “sum”, add the under/overflow bin content to first/last bin. If “hint”, draw markers at the axis to indicate presence of under/overflow. If “none”, do nothing.
**kwargs – Keyword arguments passed to underlying matplotlib functions - {‘stairs’, ‘errorbar’}.
w2 (iterable, optional) – Sum of the histogram weights squared for poissonian interval error calculation
xerr (bool or float, optional) – Size of xerr if
histtype == 'errorbar'. IfTrue, bin-width will be used.edges (bool, default: True, optional) – Specifies whether to draw first and last edges of the histogram.
binticks (bool, default: False, optional) – Attempts to draw x-axis ticks coinciding with bin boundaries if feasible.
xoffsets (bool, default: False,) – If True, the bin “centers” of plotted histograms will be offset within their bin.
- Return type:
List[Hist1DArtists]
- hist.plot.plot2d_full(self: BaseHist[Any], *, ax_dict: dict[str, Axes] | None = None, **kwargs: Any) tuple[ColormeshArtists, StairsArtists | ErrorBarArtists, StairsArtists | ErrorBarArtists]#
Plot2d_full method for BaseHist object.
Pass a dict of axes to
ax_dict, otherwise, the current figure will be used.- Parameters:
main_* (optional) – Keywords arguments prefixed with ‘’main_’’ are forwarded to the main 2D histogram plot and controls its appearance.
top_* (optional) – Keywords arguments prefixed with ‘’top_’’ are forwarded to the top histogram plot and controls its appearance.
side_* (optional) – Keywords arguments prefixed with ‘’side_’’ are forwarded to the side histogram plot and controls its appearance.
- hist.plot.plot_pull_array(__hist: BaseHist[Any], pulls: ndarray[tuple[Any, ...], dtype[Any]], ax: Axes, bar_kwargs: dict[str, Any], pp_kwargs: dict[str, Any]) PullArtists#
Plot a pull plot on the given axes
- hist.plot.plot_ratio_array(__hist: BaseHist[Any], ratio: ndarray[tuple[Any, ...], dtype[Any]], ratio_uncert: ndarray[tuple[Any, ...], dtype[Any]], ax: Axes, **kwargs: Any) RatioErrorbarArtists | RatioBarArtists#
Plot a ratio plot on the given axes
- Parameters:
central_value (float, optional) – Value of Y-axis at which to draw the horizontal reference line on the ration plot. Default is 1.0.
uncert_draw_type ({"line", "bar"}, optional) – Defines how uncertainty is drawn on the ration plot. If “line”, uncertainty is shown as error bars. If “bar”, uncertainty is shown as bars. Default is “line”.
ylim (tuple of float, optional) – Y-axis limits for the ratio plot given as (ymin, ymax) If not provided, limits are automatically determined based on the ratio values and their uncertainties.