Is there a way in QGIS to randomise the colour of all the polygons present in a single layer?

I'm currently using QGIS 3.20.3 and a lot of the plugins for this that I've found online are not compatible (including Topocolour).

New contributor
Aagwood is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Right click the polygon layer in the layers panel and go to properties -> symbology. Choose the categorized renderer from the dropdown menu on the top. As value use $id. Choose random colors as color ramp. Then click classify.

enter image description here


To get random colors, but be sure that to neighboring polygons are always in different colors, use Menu Processing / Toolbox / Cartography / Topological coloring (see documentation). Run the tool and on the output, set Data driven override > Assistant for the color and choose the field color_id as source.

enter image description here

  • Please correct the color for Crimea
    – Taras
    Jan 12 at 8:46
  • Fuck ... that sucks ... I will write to QGIS
    – Taras
    Jan 12 at 9:15
  • OSM is something different. But many thanks! Fucking bloody russia
    – Taras
    Jan 12 at 9:26

If you want to get a fixed number of colors and want to control which ones these should be, use the "regular" Single Symbol layer rendering and set a date driven override for the color. In the assistant, as Source set the expression rand(1,5) to get 5 different colors. Select a color ramp (or create your own) from whicht QGIS picks the 5 colors.

Like this, the colors are updated every time you zoom or pan. If the colors should be fixed, creat a new attribute with Field calculator and the same expression as above. In the assistant, then select the name of this field as source. So the colors will be random, but will not change any more.

enter image description here

enter image description here

Your Answer

Aagwood is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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