Use geometric objects as matplotlib paths and patches
Project description
Use Shapely or GeoJSON-like geometric objects as matplotlib paths and patches
Requires: matplotlib, numpy, and optionally Shapely 1.2.
Example:
from matplotlib import pyplot from shapely.geometry import LineString from descartes.patch import PolygonPatch line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)]) fig = pyplot.figure(1, figsize=(7.5, 3), dpi=180) # 1 ax = fig.add_subplot(121) dilated = line.buffer(0.5) patch1 = PolygonPatch(dilated, facecolor='#99ccff', edgecolor='#6699cc') ax.add_patch(patch1) x, y = line.xy ax.plot(x, y, color='#999999') ax.set_xlim(-1, 4) ax.set_ylim(-1, 3) #2 ax = fig.add_subplot(122) patch2a = PolygonPatch(dilated, facecolor='#cccccc', edgecolor='#999999') ax.add_patch(patch2a) eroded = dilated.buffer(-0.3) # GeoJSON-like data works as well polygon = eroded.__geo_interface__ # >>> geo['type'] # 'Polygon' # >>> geo['coordinates'][0][:2] # ((0.50502525316941682, 0.78786796564403572), (0.5247963548222736, 0.8096820147509064)) patch2b = PolygonPatch(polygon, facecolor='#99ccff', edgecolor='#6699cc') ax.add_patch(patch2b) ax.set_xlim(-1, 4) ax.set_ylim(-1, 3) fig.subplots_adjust(0.0, 0.0, 1.0, 1.0, 0.1) fig.savefig('buffering.png')
See also: examples/patches.py.
Descartes is not associated with the identically named and apparently defunct project at http://descartes.sourceforge.net/.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
descartes-0.1.2.tar.gz
(3.2 kB
view details)
File details
Details for the file descartes-0.1.2.tar.gz
.
File metadata
- Download URL: descartes-0.1.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695f525c00381c60d3c1d8665936df51ed5a1b20b0fe2cf6a194a7eb0da0d3b6 |
|
MD5 | ef6831121821167ccf98cebc37e4acf5 |
|
BLAKE2b-256 | 63cb27f47e1de6b75ca551832879b756f730427e3c670596fe49ee0df2dddafe |