Zero Centered Color Ramp in QGIS

I often need zero-centered color ramps in QGIS. Here is how to quickly make them:

  1. Open up the Layer Styling Dialog.
  2. Select the column you want to use and number of classes.
  3. Select the color ramp you want to use — typically a two or three color ramp — such as green-white-red or blue-white-red.
  4. Click classify.
  5. Note the highest or lowest value in the classes (such as -152 or 80).
  6. You will want to use the largest absolute value — in this case -152.
  7. 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.
  8. Select the column you want to use. Do not click classify.
  9. You will now have a nice, zero centered, balanced color ramp for displaying your data.

1 Comment

  • Ben says:

    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!

Leave a Reply

Your email address will not be published. Required fields are marked *