Histogram.plot#
- Histogram.plot(type: Literal['frequency', 'pdf', 'probability', 'cf', 'cumulative', 'cdf', 'normalized', 'ncdf'] = 'frequency', block: bool = False, filled: bool | None = None, stats: bool = True, style: str = 'stack', cursor: bool = False, alpha: float = 0.5, title: str | None = None, log: bool = False, samescale: bool = False, ax: Axes | None = None, bar: bool | None = None, **kwargs: Any) None[source][source]#
Plot histogram
- Parameters:
type – histogram type, one of: ‘frequency’ [default], ‘pdf’/’probability’, ‘cf’/’cumulative’, ‘cdf’/’normalized’; ‘ncdf’ is accepted as a deprecated alias for ‘cdf’
block (bool, optional) – hold plot, defaults to False
filled (bool, optional) – use a filled stairs plot, defaults to True for frequency plot, False for other plots
stats (bool, optional) – draw vertical lines for mean (solid) and median (dashed), defaults to True
style (str, optional) – Style for multiple plots, one of: ‘stack’ [default], ‘overlay’
cursor (bool, optional) – enable interactive data cursor for stacked line plots, defaults to False. Cursor is ignored for
overlaystyle.alpha (float, optional) – transparency for overlay plot, defaults to 0.5
title (str, optional) – plot title, defaults to None
log (bool, optional) – use logarithmic y-axis, defaults to False
samescale (bool, optional) – synchronize the y-axis scale for all subplots, defaults to True
ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on, defaults to None (new figure)
bar – deprecated alias for
filled, usefilled=insteadkwargs – additional keyword arguments passed to Matplotlib plotting functions,
plt.stairsforsolid=Trueandplt.plotforsolid=False, andplt.Polygonforstyle='overlay'
- Raises:
ValueError – invalid histogram type
ValueError – cannot use overlay style for 1-channel histogram
Plots the histogram using Matplotlib. For a color image, the histograms of each plane are plotted separately. The
typeoption selects the type of histogram to plot:frequency,pdf/probability,cf/cumulative, orcdf/normalized(normalized cumulative, range 0 to 1).ncdfis accepted as a deprecated alias forcdf.The
styleoption selects the style for plotting multiple planes:stack: plot each plane in a separate subplot. Thecursoroption enables an interactive data cursor which displays the histogram values at the cursor position. Thefilledoption selects whether to use a filled stairs plot.overlay: plot all planes in the same axes with different colors. Thefilledoption selects whether to use a filled plot. Thealphaoption controls the transparency of the bars in the ‘’overlay’’ style.
samescalecontrols whether the y-axis scale is the same for all planes (if False, each plane is scaled independently). By default, the y-axis scale is the same for all planes, which allows for direct comparison of histogram values across planes.The
logoption uses a logarithmic scale for the y-axis, which can be useful for visualizing histograms with a large dynamic range, zero values are ignored in log plots.If
axis provided, the histogram is plotted on the given Matplotlib axes. For multi-plane histograms thestyleis overridden to ‘overlay’ since all the plots must be on one axes. Ifaxis not provided, a new figure and axes are created.>>> from machinevisiontoolbox import Image >>> im = Image.Read('street.png') >>> hist = im.hist() >>> print(hist) histogram with 256 bins: xrange 0 - 255, yrange 21 - 11429 >>> hist.plot() # standard frequency plot >>> hist.plot(type='cdf') # CDF plot
(
Source code,png,hires.png,pdf)
(
Source code,png,hires.png,pdf)
For multi-plane (color) images, the histograms of each plane can be plotted separately in stacked subplots or overlaid on the same axes.
>>> from machinevisiontoolbox import Image >>> im = Image.Read('flowers1.png') >>> im.hist().plot(style='stack', filled=True) >>> im.hist().plot(style='overlay', filled=True, alpha=0.5)
(
Source code,png,hires.png,pdf)
(
Source code,png,hires.png,pdf)