Class: QgsGraduatedSymbolRenderer

class qgis.core.QgsGraduatedSymbolRenderer(attrName: str = '', ranges: Iterable[QgsRendererRange] = [])

Bases: QgsFeatureRenderer

Parameters
  • attrName (str = '') –

  • ranges

Custom = 5
EqualInterval = 0
GraduatedColor = 0
class GraduatedMethod

Bases: int

GraduatedSize = 1
Jenks = 2
class Mode

Bases: int

Pretty = 4
Quantile = 1
StdDev = 3
accept(self, visitor: QgsStyleEntityVisitorInterface) → bool
Parameters

visitor (QgsStyleEntityVisitorInterface) –

Return type

bool

addBreak(self, breakValue: float, updateSymbols: bool = True)

Add a breakpoint by splitting existing classes so that the specified value becomes a break between two classes.

Parameters
  • breakValue (float) – position to insert break

  • updateSymbols (bool = True) – set to True to reapply ramp colors to the new symbol ranges

New in version 2.9.

addClass(self, symbol: QgsSymbol)
Parameters

symbol (QgsSymbol) –

addClassLowerUpper(self, lower: float, upper: float)

Note

available in Python bindings as addClassLowerUpper

Parameters
  • lower (float) –

  • upper (float) –

addClassRange(self, range: QgsRendererRange)

Note

available in Python bindings as addClassRange

Parameters

range (QgsRendererRange) –

astride(self) → bool

Returns if we want to have a central class astride the pivot value

New in version 3.4.

Deprecated since version QGIS: 3.10 use classficationMethod instead

Return type

bool

calcEqualIntervalBreaks(minimum: float, maximum: float, classes: int, useSymmetricMode: bool, symmetryPoint: float, astride: bool) → List[float]

Compute the equal interval classification

Parameters
  • minimum (float) – The minimum value of the distribution

  • maximum (float) – The maximum value of the distribution

  • classes (int) – The number of classes desired

  • useSymmetricMode (bool) – A bool indicating if we want to have classes and hence colors ramp symmetric around a value

  • symmetryPoint (float) – The point around which we want a symmetry

  • astride (bool) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )

Deprecated since version QGIS: 3.10 use QgsClassificationEqualInterval class instead

Return type

List[float]

calculateLabelPrecision(self, updateRanges: bool = True)

Reset the label decimal places to a numberbased on the minimum class interval

Parameters

updateRanges (bool = True) – if True then ranges currently using the default label will be updated

New in version 2.6.

capabilities(self) → QgsFeatureRenderer.Capabilities
Return type

QgsFeatureRenderer.Capabilities

checkLegendSymbolItem(self, key: str, state: bool = True)
Parameters
  • key (str) –

  • state (bool = True) –

classAttribute(self) → str
Return type

str

classificationMethod(self) → QgsClassificationMethod

Returns the classification method

New in version 3.10.

Return type

QgsClassificationMethod

clone(self) → QgsGraduatedSymbolRenderer
Return type

QgsGraduatedSymbolRenderer

convertFromRenderer(renderer: QgsFeatureRenderer) → QgsGraduatedSymbolRenderer

creates a QgsGraduatedSymbolRenderer from an existing renderer.

Return type

QgsGraduatedSymbolRenderer

Returns

a new renderer if the conversion was possible, otherwise 0.

New in version 2.6.

Parameters

renderer (QgsFeatureRenderer) –

convertSymbolRotation()
convertSymbolSizeScale()
copyRendererData()
create(element: QDomElement, context: QgsReadWriteContext) → QgsFeatureRenderer

create renderer from XML element

Parameters
Return type

QgsFeatureRenderer

createRenderer(vlayer: QgsVectorLayer, attrName: str, classes: int, mode: QgsGraduatedSymbolRenderer.Mode, symbol: QgsSymbol, ramp: QgsColorRamp, legendFormat: QgsRendererRangeLabelFormat = QgsRendererRangeLabelFormat(), useSymmetricMode: bool = False, symmetryPoint: float = 0, listForCboPrettyBreaks: Iterable[str] = [], astride: bool = False) → QgsGraduatedSymbolRenderer

Creates a new graduated renderer.

Parameters
  • vlayer (QgsVectorLayer) – vector layer

  • attrName (str) – attribute to classify

  • classes (int) – number of classes

  • mode (QgsGraduatedSymbolRenderer.Mode) – classification mode

  • symbol (QgsSymbol) – base symbol

  • ramp (QgsColorRamp) – color ramp for classes

  • legendFormat (QgsRendererRangeLabelFormat = QgsRendererRangeLabelFormat()) –

  • useSymmetricMode (bool = False) – A bool indicating if we want to have classes and hence colors ramp symmetric around a value

  • symmetryPoint (float = 0) – The value around which the classes will be symmetric if useSymmetricMode is checked

  • listForCboPrettyBreaks (Iterable[str] = []) – The list of potential pivot values for symmetric mode with prettybreaks mode

  • astride (bool = False) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )

Return type

QgsGraduatedSymbolRenderer

Returns

new QgsGraduatedSymbolRenderer object

Deprecated since version QGIS: 3.10

dataDefinedSizeLegend(self) → QgsDataDefinedSizeLegend

Returns configuration of appearance of legend when using data-defined size for marker symbols. Will return None if the functionality is disabled.

New in version 3.0.

Return type

QgsDataDefinedSizeLegend

deleteAllClasses(self)
deleteClass(self, idx: int)
Parameters

idx (int) –

dump(self) → str
Return type

str

filterNeedsGeometry(self) → bool
Return type

bool

graduatedMethod(self) → QgsGraduatedSymbolRenderer.GraduatedMethod

Returns the method used for graduation (either size or color)

New in version 2.10.

Return type

QgsGraduatedSymbolRenderer.GraduatedMethod

labelFormat(self) → QgsRendererRangeLabelFormat

Returns the label format used to generate default classification labels

New in version 2.6.

Deprecated since version QGIS: 3.10 use classificationMethod() and QgsClassificationMethod.setLabelFormat instead

Return type

QgsRendererRangeLabelFormat

legendClassificationAttribute(self) → str
Return type

str

legendKeyForValue(self, value: float) → str

Returns the matching legend key for a value.

Parameters

value (float) –

Return type

str

legendKeysForFeature(self, feature: QgsFeature, context: QgsRenderContext) → Set[str]
Parameters
Return type

Set[str]

legendSymbolItemChecked(self, key: str) → bool
Parameters

key (str) –

Return type

bool

legendSymbolItems(self) → List[QgsLegendSymbolItem]
Return type

List[QgsLegendSymbolItem]

legendSymbolItemsCheckable(self) → bool
Return type

bool

makeBreaksSymmetric(breaks: Iterable[float], symmetryPoint: float, astride: bool) → List[float]

Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically balanced around symmetryPoint Does not put a break on the symmetryPoint. This is done before.

Parameters
  • breaks (Iterable[float]) – The breaks of an already-done classification

  • symmetryPoint (float) – The point around which we want a symmetry

  • astride (bool) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )

New in version 3.4.

Deprecated since version QGIS: 3.10 use QgsClassificationMethod.makeBreaksSymmetric instead

Return type

List[float]

maxSymbolSize(self) → float

Returns the max symbol size when graduated by size

New in version 2.10.

Return type

float

minSymbolSize(self) → float

Returns the min symbol size when graduated by size

New in version 2.10.

Return type

float

mode(self) → QgsGraduatedSymbolRenderer.Mode

Deprecated since version QGIS: 3.10 use classficationMethod instead

Return type

QgsGraduatedSymbolRenderer.Mode

moveClass(self, from_: int, to: int)

Moves the category at index position from to index position to.

Parameters
  • from (int) –

  • to (int) –

originalSymbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol
Parameters
Return type

QgsSymbol

rangeForValue(self, value: float) → QgsRendererRange

Returns the renderer range matching the provided value, or None if no range matches the value.

New in version 3.10.1.

Parameters

value (float) –

Return type

QgsRendererRange

ranges(self) → List[QgsRendererRange]
Return type

List[QgsRendererRange]

rangesHaveGaps(self) → bool

Tests whether classes assigned to the renderer have gaps between the ranges.

Return type

bool

Returns

True if ranges have gaps

New in version 2.10.

rangesOverlap(self) → bool

Tests whether classes assigned to the renderer have ranges which overlap.

Return type

bool

Returns

True if ranges overlap

New in version 2.10.

renderFeatureWithSymbol()
renderVertexMarker()
renderVertexMarkerPolygon()
renderVertexMarkerPolyline()
save(self, doc: QDomDocument, context: QgsReadWriteContext) → QDomElement
Parameters
Return type

QDomElement

setAstride(self, astride: bool)

Set if we want a central class astride the pivot value

New in version 3.4.

Deprecated since version QGIS: 3.10 use classficationMethod instead

Parameters

astride (bool) –

setClassAttribute(self, attr: str)
Parameters

attr (str) –

setClassificationMethod(self, method: QgsClassificationMethod)

Defines the classification method This will take ownership of the method

New in version 3.10.

Parameters

method (QgsClassificationMethod) –

setDataDefinedSizeLegend(self, settings: QgsDataDefinedSizeLegend)

Configures appearance of legend when renderer is configured to use data-defined size for marker symbols. This allows configuring for which values (symbol sizes) should be shown in the legend, whether to display different symbol sizes collapsed in one legend node or separated across multiple legend nodes etc.

When renderer does not use data-defined size or does not use marker symbols, these settings will be ignored. Takes ownership of the passed settings objects. None is a valid input that disables data-defined size legend.

New in version 3.0.

Parameters

settings (QgsDataDefinedSizeLegend) –

setGraduatedMethod(self, method: QgsGraduatedSymbolRenderer.GraduatedMethod)

set the method used for graduation (either size or color)

New in version 2.10.

Parameters

method (QgsGraduatedSymbolRenderer.GraduatedMethod) –

setLabelFormat(self, labelFormat: QgsRendererRangeLabelFormat, updateRanges: bool = False)

Set the label format used to generate default classification labels

Parameters
  • labelFormat (QgsRendererRangeLabelFormat) – The string appended to classification labels

  • updateRanges (bool = False) – If True then ranges ending with the old unit string are updated to the new.

New in version 2.6.

Deprecated since version QGIS: 3.10 use classificationMethod() and QgsClassificationMethod.setLabelFormat instead

setLegendSymbolItem(self, key: str, symbol: QgsSymbol)
Parameters
setMode(self, mode: QgsGraduatedSymbolRenderer.Mode)

Deprecated since version QGIS: 3.10 use classficationMethod instead

Parameters

mode (QgsGraduatedSymbolRenderer.Mode) –

setSourceColorRamp(self, ramp: QgsColorRamp)

Sets the source color ramp.

Parameters

ramp (QgsColorRamp) – color ramp. Ownership is transferred to the renderer

setSourceSymbol(self, sym: QgsSymbol)

Sets the source symbol for the renderer, which is the base symbol used for the each classes’ symbol before applying the classes’ color.

Parameters

sym (QgsSymbol) – source symbol, ownership is transferred to the renderer

See also

sourceSymbol()

setSymbolSizes(self, minSize: float, maxSize: float)

set varying symbol size for classes

Note

the classes must already be set so that symbols exist

New in version 2.10.

Parameters
  • minSize (float) –

  • maxSize (float) –

setSymmetryPoint(self, symmetryPoint: float)

Set the pivot point

New in version 3.4.

Deprecated since version QGIS: 3.10 use classficationMethod instead

Parameters

symmetryPoint (float) –

setUseSymmetricMode(self, useSymmetricMode: bool)

Set if we want to classify symmetric around a given value

New in version 3.4.

Deprecated since version QGIS: 3.10 use classficationMethod instead

Parameters

useSymmetricMode (bool) –

sortByLabel(self, order: Qt.SortOrder = Qt.AscendingOrder)
Parameters

order (Qt.SortOrder = Qt.AscendingOrder) –

sortByValue(self, order: Qt.SortOrder = Qt.AscendingOrder)
Parameters

order (Qt.SortOrder = Qt.AscendingOrder) –

sourceColorRamp(self) → QgsColorRamp

Returns the source color ramp, from which each classes’ color is derived.

See also

sourceSymbol()

Return type

QgsColorRamp

sourceSymbol(self) → QgsSymbol

Returns the renderer’s source symbol, which is the base symbol used for the each classes’ symbol before applying the classes’ color.

Return type

QgsSymbol

startRender(self, context: QgsRenderContext, fields: QgsFields)
Parameters
stopRender(self, context: QgsRenderContext)
Parameters

context (QgsRenderContext) –

symbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol
Parameters
Return type

QgsSymbol

symbolForValue(self, value: float) → QgsSymbol

Gets the symbol which is used to represent value.

Parameters

value (float) –

Return type

QgsSymbol

symbols(self, context: QgsRenderContext) → List[QgsSymbol]
Parameters

context (QgsRenderContext) –

Return type

List[QgsSymbol]

symmetryPoint(self) → float

Returns the pivot value for symmetric classification

New in version 3.4.

Deprecated since version QGIS: 3.10 use classficationMethod instead

Return type

float

toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, str] = {})
Parameters
  • doc (QDomDocument) –

  • element (QDomElement) –

  • props (Dict[str) –

updateClasses(self, vlayer: QgsVectorLayer, mode: QgsGraduatedSymbolRenderer.Mode, nclasses: int, useSymmetricMode: bool = False, symmetryPoint: float = 0, astride: bool = False)

Recalculate classes for a layer

Parameters
  • vlayer (QgsVectorLayer) – The layer being rendered (from which data values are calculated)

  • mode (QgsGraduatedSymbolRenderer.Mode) – The calculation mode

  • nclasses (int) – The number of classes to calculate (approximate for some modes)

  • useSymmetricMode (bool = False) – A bool indicating if we want to have classes and hence colors ramp symmetric around a value

  • symmetryPoint (float = 0) – The value around which the classes will be symmetric if useSymmetricMode is checked

  • astride (bool = False) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )

New in version 2.6.

Deprecated since version QGIS: 3.10

updateClasses(self, vl: QgsVectorLayer, nclasses: int) Recalculate classes for a layer

Parameters
  • vl – The layer being rendered (from which data values are calculated)

  • nclasses – the number of classes

updateColorRamp(self, ramp: QgsColorRamp = None)

Update the color ramp used. Also updates all symbols colors. Doesn’t alter current breaks.

Parameters

ramp (QgsColorRamp = None) – color ramp. Ownership is transferred to the renderer

updateRangeLabel(self, rangeIndex: int, label: str) → bool
Parameters
  • rangeIndex (int) –

  • label (str) –

Return type

bool

updateRangeLabels(self)

Updates the labels of the ranges

New in version 3.10.

updateRangeLowerValue(self, rangeIndex: int, value: float) → bool
Parameters
  • rangeIndex (int) –

  • value (float) –

Return type

bool

updateRangeRenderState(self, rangeIndex: int, render: bool) → bool

New in version 2.5.

Parameters
  • rangeIndex (int) –

  • render (bool) –

Return type

bool

updateRangeSymbol(self, rangeIndex: int, symbol: QgsSymbol) → bool
Parameters
  • rangeIndex (int) –

  • symbol (QgsSymbol) –

Return type

bool

updateRangeUpperValue(self, rangeIndex: int, value: float) → bool
Parameters
  • rangeIndex (int) –

  • value (float) –

Return type

bool

updateSymbols(self, sym: QgsSymbol)

Update all the symbols but leave breaks and colors. This method also sets the source symbol for the renderer.

Parameters

sym (QgsSymbol) – source symbol to use for classes. Ownership is not transferred.

useSymmetricMode(self) → bool

Returns if we want to classify symmetric around a given value

New in version 3.4.

Deprecated since version QGIS: 3.10 use classficationMethod instead

Return type

bool

usedAttributes(self, context: QgsRenderContext) → Set[str]
Parameters

context (QgsRenderContext) –

Return type

Set[str]