I'm trying to set up a legend in the lower part of the map and I have only achieved this:
legend = QgsLayoutItemLegend(layout)
legend.model().setRootGroup(root)
layout.addLayoutItem(legend)
legend.attemptMove(QgsLayoutPoint(210, 5, QgsUnitTypes.LayoutMillimeters))
This creates the legend in the layout but I want to rotate it 270°, delete the margins around the colored rectangles, hide the subgroup's title and hide the white color of the background (so that the legend's background appears transparent). I would also like to make the reduce the Spacing between legend items to 0.05 mm and change the size of the legend rectangles. The pictures show the code result and the manually edited image.