I currently have a vector layer that contains intensity polygons and are colour co-ordinated depending on the level of intensity. Within this 'Intensity' file, there are two columns
Affected_P. The file currents shows the intensity in the legend for the symbology but I would like to include the sum statistic created -
Affected_P too the legend as well. So, for example, the legend with the intensity then the
Affected_P field in brackets - 2.4 (60,000). Ideally, done within the Python Console.
The fields/columns look like this. Currently, there are multiple
Affected_P values for one intensity. I am not too sure if it would add all the values automatically when adding to the specific intensity legend you want or that you would have to add in a piece of code to this.
Invalid syntax error when I try to add the code to python, under where I have changed the symbology.
#Change symbology default_style = QgsStyle().defaultStyle() color_ramp = default_style.colorRamp('Spectral') #Spectral color ramp color_ramp.invert() layer = QgsProject().instance().mapLayersByName('Intensity') field_index = layer.fields().lookupField('Intensity') unique_values = list(layer.uniqueValues(field_index)) categories =  for value in sorted(unique_values): symbol = QgsSymbol.defaultSymbol(layer.geometryType()) category = QgsRendererCategory(value, symbol, str(value)) categories.append(category) renderer = QgsCategorizedSymbolRenderer( "intensity" || ' - ' || sum("affected_p","intensity"), categories) renderer.updateColorRamp(color_ramp)