<div dir="ltr">I am trying to automatically style a singlebandgray raster image with one of the singlebandpseudocolor color ramps. When I run this code in the QGIS Python console the raster image disappears. If I look at the image "Properties" everything seems to be set correctly and it does appear when Apply or OK buttons are clicked on. I must be missing something.<div><br></div><div><font face="monospace">layer = iface.activeLayer()<br><br>style = QgsStyle.defaultStyle()<br># Get the Reds default colorramp<br>ramp = style.colorRamp('Reds')<br>color_ramp = QgsColorRampShader()<br>color_ramp.setSourceColorRamp(ramp)<br>color_ramp.setColorRampType(QgsColorRampShader.Interpolated)<br><br>raster_shader = QgsRasterShader()<br>raster_shader.setRasterShaderFunction(color_ramp)<br># Create a new single band pseudocolor renderer<br>renderer = QgsSingleBandPseudoColorRenderer(layer.dataProvider(), layer.type(), raster_shader)<br><br>layer.setRenderer(renderer)<br>layer.triggerRepaint()</font><br></div><div><br></div><div><br></div></div>