Class: QgsHistogram

class qgis.core.QgsHistogram

Bases: sip.wrapper

Constructor for QgsHistogram.

QgsHistogram(QgsHistogram)

Calculator for a numeric histogram from a list of values.

New in version 2.9: Methods

binEdges Returns a list of edges for the histogram for a specified number of bins.
counts Returns the calculated list of the counts for the histogram bins.
optimalBinWidth Calculates the optimal bin width using the Freedman-Diaconis rule.
optimalNumberBins Returns the optimal number of bins for the source values, calculated using the Freedman-Diaconis rule.
setValues Assigns numeric source values for the histogram.

Signals

Attributes

binEdges(self, bins: int) → List[float]

Returns a list of edges for the histogram for a specified number of bins. This list will be length bins + 1, as both the first and last value are also included.

Parameters:bins – number of bins
Returns:list of bin edges

Note

values must first be specified using setValues()

counts(self, bins: int) → List[int]

Returns the calculated list of the counts for the histogram bins.

Parameters:bins – number of histogram bins
Returns:list of histogram counts

Note

values must first be specified using setValues()

optimalBinWidth(self) → float

Calculates the optimal bin width using the Freedman-Diaconis rule. Bins widths are determined by the inter-quartile range of values and the number of values.

Returns:optimal width for bins

Note

values must first be specified using setValues()

optimalNumberBins(self) → int

Returns the optimal number of bins for the source values, calculated using the Freedman-Diaconis rule. The number of bins are determined by the inter-quartile range of values and the number of values.

Returns:optimal number of bins

Note

values must first be specified using setValues()

setValues(self, values: Iterable[float])

Assigns numeric source values for the histogram.

Parameters:values – list of doubles

setValues(self, layer: QgsVectorLayer, fieldOrExpression: str, feedback: QgsFeedback = None) -> bool Assigns numeric source values for the histogram from a vector layer’s field or as the result of an expression.

Parameters:
  • layer – vector layer
  • fieldOrExpression – field name or expression to be evaluated
  • feedback – optional feedback object to allow cancelation of calculation
Returns:

true if values were successfully set