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.
OpenStreetMap: One of the World's Largest Collaborative Geospatial Projects - GIS Lounge
SVGZ Graphic: Cattle in America (2017)
SVGZ Graphic: Final USGS DRG Topographic Map Update
SVGZ Graphic: How Big is Texas?
SVGZ Graphic: Nearest Foreign Country
SVGZ Graphic: Percentage of Town Area Sloping North
SVGZ Graphic: Which is Closer - New York or Texas?
Terrain Map: Digital Terrain Models
Thematic Map: Big Foot Sightings

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!

Leave a Reply

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