Many plotting libraries can handle collections of polygons, e.g. Bokeh or HoloViews+Bokeh. However, because browser-based libraries like Bokeh and Plotly send all the polygon data to the browser, they can struggle when either the collections or the polygons themselves get large. Even natively in Python, typical formats like Shapely for representing polygons scale poorly to large polygon collections, because each polygon is wrapped up as a separate Python object, leading to a lot of duplicated storage overhead when many polygons of the same type are defined.
If you want to work with lots of polygons, here you can see how to use SpatialPandas and Dask to represent polygons efficiently in memory, fastparquet to represent them efficiently on disk, and Datashader to render them quickly in a web browser. This notebook also demonstrates how to support hovering for datashaded polygons, with Bokeh overlaying a single vector-based representation of a polygon where the mouse cursor is, while all the rest are sent to the browser only as rendered pixels. That way hover and other interactive features can be supported fully without ever needing to transfer large amounts of data or store them in the limited memory of the web browser tab.
This example plots the outlines of all the buildings in New York City. See nyc.gov for the original data and its description.
import holoviews as hv import colorcet as cc import datashader as ds import spatialpandas as spd import spatialpandas.io from dask.diagnostics import ProgressBar from holoviews.operation.datashader import ( rasterize, datashade, inspect_polygons ) hv.extension('bokeh')