Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Legendgrams are map legends that visualize the distribution of observations by color in a given map

Project description

This is a small bit of unittested, reproducible code to provide legendgrams. Legendgrams are map legends that visualize the distribution of observations by color in a given map:

Silhouettes in Brooklyn

Legendgrams are distributed by PySAL, an open source cross-platform library of spatial analysis functions written in Python. It is intended to support the development of high level applications for spatial analysis.

To use legendgrams, simply install the package using pip:

$ pip install legendgram

Then, apply the function to the figure/axis you want to have a legendgram:

>>> import pysal as ps, geopandas as gpd, matplotlib.pyplot as plt
>>> from legendgram import legendgram
>>> data = gpd.read_file(ps.examples.get_path('south.shp'))
>>> = {'init': 'epgs:4269'}
>>> data.to_crs(epsg=5070)
>>> f,ax = plt.subplots()
>>> data.plot('DV80', k=10, ax=ax, scheme='Quantiles')
>>> bins = ps.Quantiles(data['DV80'].values, k=10).bins
>>> from legendgram import legendgram
>>> import palettable.matplotlib as palmpl
>>> legendgram(f,ax,data['DV80'],bins,pal=palmpl.Viridis_10,
               legend_size=(.5,.2), # legend size in fractions of the axis
               loc = 'upper left' # matplotlib-style legend locations
               clip = (2,10) # clip the displayed range of the histogram
Example legendgram map in the US south

An example notebook is provided as well.


This is licensed under the 3-Clause BSD license. Refer to the license file for more details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for legendgram, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size legendgram-0.0.3-py2.py3-none-any.whl (7.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size legendgram-0.0.3.tar.gz (683.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page