Draw polygons more efficiently with matplotlib
matplotlibpolygonperformancebasemapgeospatial
Abstraction: Rendering 60000 geographic polygons efficiently using matplotlib basemap
Key points:
- Naive per-polygon loop adding individual Polygon patches takes ~1.5 minutes for 60,000 shapes
- Each shape has lat/lon corners converted to map x/y via basemap before creating a Polygon patch
- Pattern uses
plt.gca().add_patch(poly)in a loop — O(n) patch additions is the bottleneck - Standard solution is PatchCollection, which batches all polygons into a single artist for rendering
- Float16 (
'f2') used for coordinate arrays, which may reduce precision for some projections
Connections: Matplotlib · Data Visualization · Geospatial Visualization
Source: http://stackoverflow.com/questions/12881848/draw-polygons-more-efficiently-with-matplotlib