Manually applying a graduated colour style in QGIS means opening Layer Properties, picking a field, choosing a colour ramp, and hitting Classify. If you do this on multiple layers or regularly, it adds up. This script does it in one run.
What it does
The classify_layer.py script applies a graduated yellow → green colour classification to any numeric attribute column on the first checked vector layer. Two classification methods are supported:
discrete— divides the value range into equal-width steps of 0.1 (e.g. 0–0.1, 0.1–0.2, etc.)percentile— divides by data distribution into four quartiles (0–25%, 25–50%, 50–75%, 75–100%)
The style is applied in-place to the layer renderer — no output file is created.
What you need
- QGIS 3.28 or newer
- A vector layer with a numeric attribute column, checked (ticked) in the Layers panel
- The
classify_layer.pyscript from the GIS Utilities Pack
Steps
- Load your vector layer into QGIS and check (tick) it in the Layers panel.
- Open Plugins → Python Console → Show Editor.
- Paste the script. At the bottom, find the function call and set:
column— the name of the numeric field to classify (default:'ndvi_mean')method—'discrete'or'percentile'
- Click Run. The layer updates immediately in the canvas.
When to use each method
| Method | Best for |
|---|---|
discrete | When the data range is known and consistent (e.g. NDVI 0–1) |
percentile | When you want to show relative ranking regardless of actual values |
Percentile is particularly useful for height or custom scores where the range varies per dataset — it always fills the full colour spectrum even if actual values are clustered.
Get the script
classify_layer.py is part of the GIS Utilities Pack — four everyday QGIS automation scripts for $25 USD.