How to generate a legend on map canvas in QGIS with PyQGIS - Tutorial

QGIS is a powerful and user friendly GIS software. The user can represent points and style them according to the measured values. This tutorial deals with the legend representation on map canvas for a better geospatial data analysis. 
Legend representation is done with just 6 lines of code on PyQGIS, the Python tool of QGIS.

 

PyQGIS

from qgis.gui import *
root = QgsProject.instance().layerTreeRoot()
model = QgsLayerTreeModel(root)
view = QgsLayerTreeView()
view.setModel(model)
view.show()

 

Tutorial

 

 

Saul Montoya

Saul Montoya es Ingeniero Civil graduado de la Pontificia Universidad Católica del Perú en Lima con estudios de postgrado en Manejo e Ingeniería de Recursos Hídricos (Programa WAREM) de la Universidad de Stuttgart con mención en Ingeniería de Aguas Subterráneas y Hidroinformática.

Smiley face

Subscribe to our free e-newsletter for tutorials, articles, webminars, courses and more.