Zero Centered Color Ramp in QGIS
I often need zero-centered color ramps in QGIS. Here is how to quickly make them:
- Open up the Layer Styling Dialog.
- Select the column you want to use and number of classes.
- Select the color ramp you want to use — typically a two or three color ramp — such as green-white-red or blue-white-red.
- Click classify.
- Note the highest or lowest value in the classes (such as -152 or 80).
- You will want to use the largest absolute value — in this case -152.
- Put in the column box, rand(-152, 152) and click classify. If you a using a simple shapefile without many objects, you may have to expand the range slightly, e.g. rand(-200,200),Β to ensure a full ramp is generated.
- Select the column you want to use. Do not click classify.
- You will now have a nice, zero centered, balanced color ramp for displaying your data.
1 Comment
Brilliant! Thank you very much! QGIS is missing a native solution for this, in my opinion. E.g. a map of average temperatures with positive values ranging to +17Β° and negative values ranging to -6Β°. Of course the divergent colour ramp should be centered on 0, and of course the -6Β° value shouldn’t have the same colour intensity as the +17Β°. It should be comparable to +6Β°. This is a great hack to achieve this without having to manually set dozens or even hundreds of classes!