Histogram.plot#
- Histogram.plot(type='frequency', block=False, filled=None, stats=True, style='stack', cursor=False, alpha=0.5, title=None, log=False, samescale=False, ax=None, bar=None, **kwargs)[source]#
Plot histogram
- Parameters:
type (str, optional) – histogram type, one of: ‘frequency’ [default], ‘cdf’, ‘ncdf’
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,cdforncdf(normalized cumulative in the range 0 to 1).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)