Class: QgsHistogram

class qgis.core.QgsHistogram

Bases: sip.wrapper

Constructor for QgsHistogram.

QgsHistogram(QgsHistogram)

Calculator for a numeric histogram from a list of values.

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.

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 (int) – number of bins

Return type

List[float]

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 (int) – number of histogram bins

Return type

List[int]

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.

Return type

float

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.

Return type

int

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 (Iterable[float]) – 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 cancellation of calculation

Returns

True if values were successfully set