Raster Boxplot for QGIS
A QGIS Processing script that mimics GRASS’s r.boxplot. It draws a boxplot
of raster values, optionally grouped by categories from a zonal (categorical)
raster, and renders it in an interactive matplotlib window inside QGIS.

Features
- Boxplot of a single raster, or grouped boxplots by zones from a second raster.
- Zone ordering: natural, by ascending median, or by descending median.
- Notches, outlier toggle, whisker IQR multiplier, horizontal orientation.
- Rotated category labels, adjustable font size and DPI.
- Optional sampling for large rasters (fraction of valid cells).
- Fill boxes with the zonal raster’s color table (
-c equivalent); the median
line automatically shifts lighter or darker to stay readable.
- Interactive matplotlib window with pan, zoom, and save toolbar, or export
to PNG / PDF / SVG.
Requirements
- QGIS 3.x with the Processing framework (bundled).
- Python packages:
numpy, matplotlib, gdal, PyQt5 — all shipped with
standard QGIS installations.
Installation
- Download raster_boxplot.py from github
- In QGIS, open the Processing Toolbox (
Ctrl+Alt+T).
- Click the Python icon at the top of the toolbox and choose
Add Script to Toolbox….
- Select
raster_boxplot.py.
The algorithm appears under Scripts → Raster plots → Raster boxplot.
To update the script later, edit it in place (right-click → Edit script) or
re-add it via the same menu.
Usage
Open the algorithm and set:
- Input raster — the raster whose values you want to summarize.
- Zonal raster (optional) — a categorical raster; one box per category.
- Zone ordering — natural, ascending median, descending median.
- Flags for horizontal boxes, notches, outliers, grid, whisker range, etc.
- Color boxes from zonal raster color table — uses the zones layer’s
current QGIS style (paletted or singleband pseudocolor) or its embedded
GDAL color table.
- Output image (optional) — leave empty for an interactive window, or
provide a path to save as PNG, PDF, or SVG.
Notes
- The zones raster must share shape (rows × columns) with the input raster.
If not, align them first with Processing → Align rasters.
- For very large rasters, set Sample fraction to a value between 0 and 1
so only that share of valid cells is used.
- When zonal colors are enabled but the zones layer has no palette or style,
boxes fall back to gray with a warning in the log.
AUTHOR
Paulo van Breugel, HAS green
academy, Innovative Biomonitoring research
group,
Climate-robust Landscapes research
group