TransWikia.com

Adjusting space between symbols in legend using PyGIS and Print Layout

Geographic Information Systems Asked on July 31, 2021

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

One Answer

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

Correct answer by ThomasG77 on July 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP