Using continuous color band for raster legend in QGIS composer legend?

Update: QGIS 3.18 now has built in support for gradient color band legend items, so the previous workarounds are no longer necessary!

For earlier versions:

Another option is to add a rectangle shape to the composition, then style the rectangle using a gradient fill with the same color ramp as your raster. This can be done directly in QGIS, no image editing or html required.

enter image description here


A bit of a hack round to get composer to do this in QGIS 3

Add your legend, then adjust the symbol size in your legend to something small (example is 1.5mm). You'll still see white lines dividing the colour bands, these seem to relate to the font size for the legend text so set this to zero.

You can then add manual labels along the gradient and a rectangle to mask the legend text, or set that text to white.

This doesn't give a perfect gradient as some small white lines remain but for my purposes this was good enough.

Edit; This was tested on QGIS version 3.4.1-Madeira

As below;

enter image description here


A workaround without pictures is to add the gradient using a HTML frame and some CSS magic:

<html> <head> <style type="text/css"> 
body { background: -webkit-linear-gradient(left,red,orange,yellow,green);  }
* { color: white;  font-family: "Source Sans Pro", Arial, sans; font-size: 24px;  }
</style></head>
<body> <div style="float:left">low value</div>
       <div style="float:right">high value</div>
</body> </html>

enter image description here