Descartes

1.1.0 · deprecated · verified Sun Apr 12

Descartes is a Python library that enables the use of geometric objects, typically from the Shapely library, as Matplotlib paths and patches. It provides a convenient way to integrate vector geometries into Matplotlib plots. The current version is 1.1.0, released on January 17, 2017. Due to its last release date, the project has a very slow or effectively ceased release cadence, leading to compatibility challenges with newer dependencies.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a `shapely.geometry.Polygon` and then render it on a Matplotlib axis using `descartes.PolygonPatch`. The `PolygonPatch` converts the geometric object into a displayable Matplotlib patch.

import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from descartes import PolygonPatch

# Define a simple polygon using Shapely
polygon = Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])

# Create a Matplotlib figure and axes
fig, ax = plt.subplots()

# Create a PolygonPatch from the Shapely Polygon
# You can customize color (fc), edge color (ec), alpha, etc.
patch = PolygonPatch(polygon, fc='blue', ec='black', alpha=0.5, zorder=2)

# Add the patch to the axes
ax.add_patch(patch)

# Set axes limits to display the polygon
minx, miny, maxx, maxy = polygon.bounds
ax.set_xlim(minx - 0.1, maxx + 0.1)
ax.set_ylim(miny - 0.1, maxy + 0.1)
ax.set_aspect('equal', adjustable='box') # Keep aspect ratio

plt.title("Shapely Polygon plotted with Descartes")
plt.show()

view raw JSON →