def get_quantile_ramp_item_list(layer): """ Returns the quantile ramp item list and overrides the ramp items labels with our custom categories. We use a dummy shader function to help us with the quantile classification """ stats = layer.dataProvider().bandStatistics( 1, QgsRasterBandStats.All) min_val = stats.minimumValue max_value = stats.maximumValue colors = [ QColor('#4c724b'), QColor('#89a167'), QColor('#d9d98d'), QColor('#b08d64'), QColor('#8a514a') ] dummy_shader = QgsColorRampShader( minimumValue=min_val, maximumValue=max_val, colorRamp=QgsPresetSchemeColorRamp(colors=colors), type=QgsColorRampShader.Discrete, classificationMode=QgsColorRampShader.Quantile) dummy_shader.classifyColorRamp(classes=5, band=1, input=layer.dataProvider()) labels = ['Very low', 'Low', 'Moderate', 'High', 'Very high'] ramp_items = [] for i, ramp_item in enumerate(dummy_shader.colorRampItemList()): ramp_item.label = labels[i] ramp_items.append(ramp_item) return ramp_items