3

I have been trying to format a legend in order that it appears as a color bar under the map (in the print layout). I have been able to modify almost everything but I can't find a command to reduce the space between symbols to zero (mm).

Does anyone know how to do this?

The code until now is the following:

legend = QgsLayoutItemLegend(layout)
legend.model().setRootGroup(root)
layout.addLayoutItem(legend)
legend.attemptMove(QgsLayoutPoint(30, 200, QgsUnitTypes.LayoutMillimeters))
legend.setAutoUpdateModel(True)
legend.setItemRotation(270)
legend.setBackgroundEnabled(False)
legend.setFrameEnabled(False)
legend.setDrawRasterStroke(True)
legend.setSymbolHeight(11.0)
legend.setSymbolWidth(4.0)
legend.setEqualColumnWidth(0.0)
legend.setLineSpacing(0)
legend.setColumnSpace(0.0)
legend.setBoxSpace(0.0)

enter image description here

1 Answer 1

4

You should try the following

legend.rstyle(QgsLegendStyle.Symbol).setMargin( QgsLegendStyle.Top , 0)

This variable above is the value I change in following animation

Spacing between symbol in layout legend

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.