Class: QgsGraduatedSymbolRenderer¶
A vector feature renderer which uses numeric attributes to classify features into different ranges.
Class Hierarchy¶
Base classes¶
Abstract base class for all 2D vector feature renderers. |
Enums
Methods for modifying symbols by range in a graduated symbol renderer. |
Methods
Add a breakpoint by splitting existing classes so that the specified value becomes a break between two classes. |
|
Adds a class to the renderer, with the specified symbol. |
|
Adds a class to the renderer, with the specified lower and upper bounds. |
|
Adds a class to the renderer, with the specified range. |
|
Returns if we want to have a central class astride the pivot value |
|
Reset the label decimal places to a numberbased on the minimum class interval |
|
Returns the attribute name (or expression) used for the classification. |
|
Returns the classification method |
|
Returns configuration of appearance of legend when using data-defined size for marker symbols. |
|
Returns the method used for graduation (either size or color). |
|
Returns the label format used to generate default classification labels |
|
Returns the matching legend key for a value. |
|
Returns the max symbol size when graduated by size |
|
Returns the min symbol size when graduated by size |
|
Moves the category at index position from to index position to. |
|
Returns the renderer range matching the provided value, or |
|
Returns a list of all ranges used in the classification. |
|
Tests whether classes assigned to the renderer have gaps between the ranges. |
|
Tests whether classes assigned to the renderer have ranges which overlap. |
|
Set if we want a central class astride the pivot value |
|
Sets the attribute name (or expression) used for the classification. |
|
Defines the classification method This will take ownership of the method |
|
Configures appearance of legend when renderer is configured to use data-defined size for marker symbols. |
|
Set the method used for graduation (either size or color). |
|
Set the label format used to generate default classification labels |
|
Sets the source color ramp. |
|
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol before applying the classes' color. |
|
set varying symbol size for classes |
|
Set the pivot point |
|
Set if we want to classify symmetric around a given value |
|
Returns the source color ramp, from which each classes' color is derived. |
|
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol before applying the classes' color. |
|
Gets the symbol which is used to represent value. |
|
Returns the pivot value for symmetric classification |
|
Recalculate classes for a layer |
|
Update the color ramp used. |
|
Updates the labels of the ranges |
|
Update all the symbols but leave breaks and colors. |
|
Returns if we want to classify symmetric around a given value |
Static Methods
Compute the equal interval classification |
|
creates a |
|
create renderer from XML element |
|
Creates a new graduated renderer. |
|
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. |
Attributes
- class qgis.core.QgsGraduatedSymbolRenderer[source]¶
Bases:
QgsFeatureRenderer
- Custom = 5¶
- EqualInterval = 0¶
- class GraduatedMethod(*values)¶
Bases:
IntEnum
Methods for modifying symbols by range in a graduated symbol renderer.
Note
Prior to QGIS 3.26 this was available as
QgsGraduatedSymbolRenderer
.GraduatedMethodAdded in version 3.26.
Color
: Alter color of symbolsAvailable as
QgsGraduatedSymbolRenderer.GraduatedColor
in older QGIS releases.Size
: Alter size of symbolsAvailable as
QgsGraduatedSymbolRenderer.GraduatedSize
in older QGIS releases.
- Jenks = 2¶
- class Mode¶
Bases:
int
- Pretty = 4¶
- Quantile = 1¶
- StdDev = 3¶
- addBreak(self, breakValue: float, updateSymbols: bool = True)[source]¶
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
- addClass(self, symbol: QgsSymbol | None)[source]¶
Adds a class to the renderer, with the specified
symbol
.- Parameters:
symbol (Optional[QgsSymbol])
- addClassLowerUpper(self, lower: float, upper: float)¶
Adds a class to the renderer, with the specified
lower
andupper
bounds.- Parameters:
lower (float)
upper (float)
- addClassRange(self, range: QgsRendererRange)¶
Adds a class to the renderer, with the specified
range
.- Parameters:
range (QgsRendererRange)
- astride(self) bool [source]¶
Returns if we want to have a central class astride the pivot value
Added in version 3.4.
Deprecated since version 3.10: Use
classficationMethod()
instead.- Return type:
bool
- static 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 3.10: Use
QgsClassificationEqualInterval
class instead.- Return type:
List[float]
- calculateLabelPrecision(self, updateRanges: bool = True)[source]¶
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
- classAttribute(self) str [source]¶
Returns the attribute name (or expression) used for the classification.
See also
- Return type:
str
- classificationMethod(self) QgsClassificationMethod | None [source]¶
Returns the classification method
Added in version 3.10.
- Return type:
Optional[QgsClassificationMethod]
- static convertFromRenderer(renderer: QgsFeatureRenderer | None) QgsGraduatedSymbolRenderer | None [source]¶
creates a
QgsGraduatedSymbolRenderer
from an existing renderer.- Return type:
Optional[QgsGraduatedSymbolRenderer]
- Returns:
a new renderer if the conversion was possible, otherwise
None
.- Parameters:
renderer (Optional[QgsFeatureRenderer])
- static create(element: QDomElement, context: QgsReadWriteContext) QgsFeatureRenderer | None [source]¶
create renderer from XML element
- Parameters:
element (QDomElement)
context (QgsReadWriteContext)
- Return type:
Optional[QgsFeatureRenderer]
- static createRenderer(vlayer: QgsVectorLayer | None, attrName: str | None, classes: int, mode: QgsGraduatedSymbolRenderer.Mode, symbol: QgsSymbol | None, ramp: QgsColorRamp | None, legendFormat: QgsRendererRangeLabelFormat = QgsRendererRangeLabelFormat(), useSymmetricMode: bool = False, symmetryPoint: float = 0, listForCboPrettyBreaks: Iterable[str | None] = [], astride: bool = False) QgsGraduatedSymbolRenderer | None [source]¶
Creates a new graduated renderer.
- Parameters:
vlayer (Optional[QgsVectorLayer]) – vector layer
attrName (Optional[str]) – attribute to classify
classes (int) – number of classes
mode (QgsGraduatedSymbolRenderer.Mode) – classification mode
symbol (Optional[QgsSymbol]) – base symbol
ramp (Optional[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[Optional[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:
Optional[QgsGraduatedSymbolRenderer]
- Returns:
new
QgsGraduatedSymbolRenderer
object
Deprecated since version 3.10.
- dataDefinedSizeLegend(self) QgsDataDefinedSizeLegend | None [source]¶
Returns configuration of appearance of legend when using data-defined size for marker symbols. Will return
None
if the functionality is disabled.- Return type:
Optional[QgsDataDefinedSizeLegend]
- graduatedMethod(self) Qgis.GraduatedMethod [source]¶
Returns the method used for graduation (either size or color).
See also
- Return type:
- labelFormat(self) QgsRendererRangeLabelFormat [source]¶
Returns the label format used to generate default classification labels
Deprecated since version 3.10: Use
classificationMethod()
andQgsClassificationMethod
.setLabelFormat instead.- Return type:
- legendKeyForValue(self, value: float) str [source]¶
Returns the matching legend key for a value.
- Parameters:
value (float)
- Return type:
str
- static makeBreaksSymmetric(breaks: Iterable[float], symmetryPoint: float, astride: bool) List[float] [source]¶
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] )
Added in version 3.4.
Deprecated since version 3.10: Use
QgsClassificationMethod
.makeBreaksSymmetric instead.- Return type:
List[float]
- maxSymbolSize(self) float [source]¶
Returns the max symbol size when graduated by size
- Return type:
float
- minSymbolSize(self) float [source]¶
Returns the min symbol size when graduated by size
- Return type:
float
- mode(self) QgsGraduatedSymbolRenderer.Mode [source]¶
Deprecated since version 3.10.
Use
classficationMethod()
instead.- Return type:
- moveClass(self, from_: int, to: int)[source]¶
Moves the category at index position from to index position to.
- Parameters:
from (int)
to (int)
- rangeForValue(self, value: float) QgsRendererRange | None [source]¶
Returns the renderer range matching the provided
value
, orNone
if no range matches the value.Added in version 3.10.1.
- Parameters:
value (float)
- Return type:
Optional[QgsRendererRange]
- ranges(self) List[QgsRendererRange] ¶
Returns a list of all ranges used in the classification.
- Return type:
List[QgsRendererRange]
- rangesHaveGaps(self) bool [source]¶
Tests whether classes assigned to the renderer have gaps between the ranges.
- Return type:
bool
- Returns:
True
if ranges have gaps
- rangesOverlap(self) bool [source]¶
Tests whether classes assigned to the renderer have ranges which overlap.
- Return type:
bool
- Returns:
True
if ranges overlap
- setAstride(self, astride: bool)[source]¶
Set if we want a central class astride the pivot value
Added in version 3.4.
Deprecated since version 3.10: Use
classficationMethod()
instead.- Parameters:
astride (bool)
- setClassAttribute(self, attr: str | None)[source]¶
Sets the attribute name (or expression) used for the classification.
See also
- Parameters:
attr (Optional[str])
- setClassificationMethod(self, method: QgsClassificationMethod | None)[source]¶
Defines the classification method This will take ownership of the method
Added in version 3.10.
- Parameters:
method (Optional[QgsClassificationMethod])
- setDataDefinedSizeLegend(self, settings: QgsDataDefinedSizeLegend | None)[source]¶
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.- Parameters:
settings (Optional[QgsDataDefinedSizeLegend])
- setGraduatedMethod(self, method: Qgis.GraduatedMethod)[source]¶
Set the
method
used for graduation (either size or color).See also
- Parameters:
method (Qgis.GraduatedMethod)
- setLabelFormat(self, labelFormat: QgsRendererRangeLabelFormat, updateRanges: bool = False)[source]¶
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.
Deprecated since version 3.10: Use
classificationMethod()
andQgsClassificationMethod
.setLabelFormat instead.
- setMode(self, mode: QgsGraduatedSymbolRenderer.Mode)[source]¶
Deprecated since version 3.10.
Use
classficationMethod()
instead.- Parameters:
- setSourceColorRamp(self, ramp: QgsColorRamp | None)[source]¶
Sets the source color ramp.
- Parameters:
ramp (Optional[QgsColorRamp]) – color ramp. Ownership is transferred to the renderer
- setSourceSymbol(self, sym: QgsSymbol | None)[source]¶
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 (Optional[QgsSymbol]) – source symbol, ownership is transferred to the renderer
See also
See also
- setSymbolSizes(self, minSize: float, maxSize: float)[source]¶
set varying symbol size for classes
Note
the classes must already be set so that symbols exist
- Parameters:
minSize (float)
maxSize (float)
- setSymmetryPoint(self, symmetryPoint: float)[source]¶
Set the pivot point
Added in version 3.4.
Deprecated since version 3.10: Use
classficationMethod()
instead.- Parameters:
symmetryPoint (float)
- setUseSymmetricMode(self, useSymmetricMode: bool)[source]¶
Set if we want to classify symmetric around a given value
Added in version 3.4.
Deprecated since version 3.10: Use
classficationMethod()
instead.- Parameters:
useSymmetricMode (bool)
- sortByLabel(self, order: Qt.SortOrder = Qt.AscendingOrder)[source]¶
- Parameters:
order (Qt.SortOrder = Qt.AscendingOrder)
- sortByValue(self, order: Qt.SortOrder = Qt.AscendingOrder)[source]¶
- Parameters:
order (Qt.SortOrder = Qt.AscendingOrder)
- sourceColorRamp(self) QgsColorRamp | None [source]¶
Returns the source color ramp, from which each classes’ color is derived.
See also
See also
- Return type:
Optional[QgsColorRamp]
- sourceSymbol(self) QgsSymbol | None [source]¶
Returns the renderer’s source symbol, which is the base symbol used for the each classes’ symbol before applying the classes’ color.
See also
See also
- Return type:
Optional[QgsSymbol]
- symbolForValue(self, value: float) QgsSymbol | None [source]¶
Gets the symbol which is used to represent
value
.- Parameters:
value (float)
- Return type:
Optional[QgsSymbol]
- symmetryPoint(self) float [source]¶
Returns the pivot value for symmetric classification
Added in version 3.4.
Deprecated since version 3.10: Use
classficationMethod()
instead.- Return type:
float
- updateClasses(self, vlayer: QgsVectorLayer | None, mode: QgsGraduatedSymbolRenderer.Mode, nclasses: int, useSymmetricMode: bool = False, symmetryPoint: float = 0, astride: bool = False)[source]¶
Recalculate classes for a layer
- Parameters:
vlayer (Optional[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] )
Deprecated since version 3.10.
- updateClasses(self, vl: QgsVectorLayer | None, nclasses: int) str [source]
Recalculate classes for a layer
- Parameters:
vl (Optional[QgsVectorLayer]) – The layer being rendered (from which data values are calculated)
nclasses (int) – the number of classes
- Return type:
str
- Returns:
Optional parameter for error reporting
- updateColorRamp(self, ramp: QgsColorRamp | None = None)[source]¶
Update the color ramp used. Also updates all symbols colors. Doesn’t alter current breaks.
- Parameters:
ramp (Optional[QgsColorRamp] = None) – color ramp. Ownership is transferred to the renderer
- updateRangeLabel(self, rangeIndex: int, label: str | None) bool [source]¶
- Parameters:
rangeIndex (int)
label (Optional[str])
- Return type:
bool
- updateRangeLowerValue(self, rangeIndex: int, value: float) bool [source]¶
- Parameters:
rangeIndex (int)
value (float)
- Return type:
bool
- updateRangeRenderState(self, rangeIndex: int, render: bool) bool [source]¶
- Parameters:
rangeIndex (int)
render (bool)
- Return type:
bool
- updateRangeSymbol(self, rangeIndex: int, symbol: QgsSymbol | None) bool [source]¶
- Parameters:
rangeIndex (int)
symbol (Optional[QgsSymbol])
- Return type:
bool
- updateRangeUpperValue(self, rangeIndex: int, value: float) bool [source]¶
- Parameters:
rangeIndex (int)
value (float)
- Return type:
bool