Class: QgsColorRamp

Abstract base class for color ramps.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone(), color(), count(), properties(), type(), value()

Class Hierarchy

Inheritance diagram of qgis.core.QgsColorRamp

Subclasses

QgsColorBrewerColorRamp

Color ramp utilising “Color Brewer” preset color schemes.

QgsGradientColorRamp

Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra color stops.

QgsLimitedRandomColorRamp

Constrained random color ramp, which returns random colors based on preset parameters.

QgsPresetSchemeColorRamp

A scheme based color ramp consisting of a list of predefined colors.

QgsRandomColorRamp

A color ramp consisting of random colors, constrained within component ranges.

Abstract Methods

clone

Creates a clone of the color ramp.

color

Returns the color corresponding to a specified value.

count

Returns number of defined colors, or -1 if undefined

properties

Returns a string map containing all the color ramp's properties.

type

Returns a string representing the color ramp type.

value

Returns relative value between [0,1] of color at specified index

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsColorRamp. See the FAQ for more details.

invert

Inverts the ordering of the color ramp.

Static Methods

rampTypes

Returns a list of available ramp types, where the first value in each item is the QgsColorRamp.type() string and the second is a user friendly, translated name for the color ramp type.

class qgis.core.QgsColorRamp[source]

Bases: object

abstract clone(self) QgsColorRamp | None[source]

Creates a clone of the color ramp.

Return type:

Optional[QgsColorRamp]

abstract color(self, value: float) QColor[source]

Returns the color corresponding to a specified value.

Parameters:

value (float) – value between [0, 1] inclusive

Return type:

QColor

Returns:

color for value

abstract count(self) int[source]

Returns number of defined colors, or -1 if undefined

Return type:

int

virtual invert(self)[source]

Inverts the ordering of the color ramp.

abstract properties(self) Dict[str, Any][source]

Returns a string map containing all the color ramp’s properties.

Return type:

Dict[str, Any]

static rampTypes() List[Tuple[str, str]]

Returns a list of available ramp types, where the first value in each item is the QgsColorRamp.type() string and the second is a user friendly, translated name for the color ramp type.

The ramp types are returned in a order of precedence for exposing in UI, with more commonly used types listed first.

Added in version 3.16.

Return type:

List[Tuple[str, str]]

abstract type(self) str[source]

Returns a string representing the color ramp type.

Return type:

str

abstract value(self, index: int) float[source]

Returns relative value between [0,1] of color at specified index

Parameters:

index (int)

Return type:

float