Is there any way of generating random softer colours using QGIS?

I've just spent some while looking, unsuccessfully. There seems to be no way to influence the "seed" colour if they're random unlike other times when the colour/symbol is taken from the semi-default one in the options window. It is common for Landscape Character to be presented with softer colours, usually across the spectrum and there are too many categories to do it manually although this example only shows a small area. example of the muted colours

2 Answers 2

  1. In your layer attribute table, create a new text field (min 11 characters length).
  2. In your QGIS field calculator, put this expression for update this field :
  rand(0, 360), -- all hue (0 to 360)
  rand(10, 35), -- only "muted" saturation (0 to 100)
  rand(50, 100) -- only "colored" value (0 to 100)
  1. Save the edit.
  2. Open the layer styling panel or layer properties > symbology tab
  3. Choose Single symbol symbology and define the fill color as data defined (small dropdown to the right) by the new created and updated field.

Et voilà !

If you want specific colors, you can reduce or fix the hue, if you want more "muted" colors, you can reduce the saturation and if you want more darker colors, play with the value.


You can use QGIS expressions to change or define certain characteristics of colors. If you define this characteristic as custom variable, you have it at hand everywhere in QGIS where colors play a role to adjust it accordingly. You can define the color as a completely random pastel color or as a pastel ("weaker") variant of a defined color.

See a quick animated version with the random version:

enter image description here

  1. To change any characteristic of a color (like hue, saturation etc.), use set_color_part. See below, Expression to set color to pastel for the exact expression to use if you want to change a solid color to it's pastel version. If you just want to do that, you're done. If you want to use it everywhere in QGIS, proceed to step 2.

  2. It can be set as a project variable (let's call it pastel_color) and than automatically be used to convert all existing colors in your project to a pastel version of it. The custom variable is defined in the project properties. Once defined there, you just need to add eval(@pastel_color) in data driven override of those colors you want to set in pastel.

QGIS custom project variable to change colors to a pastel satuarion automatically

If you play around with the saturation value (20, red box, in the screenshot above), it will affect all colors at once that refer to this variable.

Expression to set color to pastel

The expression to use (either for the variable or paste it individually as data driven override for colors) is as follows. This is to set the existing color to a pastel version. If you want completely random colors in pastel, simply replace the color_part( @symbol_color , '[color]') part for each of the three colors with rand (0,254):

        color_part(  @symbol_color , 'red'),
        color_part(  @symbol_color , 'green'),
        color_part(  @symbol_color , 'blue')

It sets the saturation of the input color to 20%: change this value in the second last row as you like to get stronger or weaker colors.

See here the animated gif, using the expression from above without random values, just changing the selected "solid" color to pastel: enter image description here

See next screenshot to see how it works: the color defined for the polygon is a saturated red, in RGB: 255,0,0. The expression set_color_part(color,component,value) takes this as an input (from the variable @symbol_color: first argument of the function), than accesses the saturation component of the color (second argument) and sets it's value to 20 (third argument). Play around with this last value to find an ideal setting.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.