How do I plot Shapely polygons and objects using Matplotlib?
Use: import matplotlib.pyplot as plt x,y = polygon1.exterior.xy plt.plot(x,y) Or, more succinctly: plt.plot(*polygon1.exterior.xy)
Use: import matplotlib.pyplot as plt x,y = polygon1.exterior.xy plt.plot(x,y) Or, more succinctly: plt.plot(*polygon1.exterior.xy)
Installed shapely using pip, and had the same problem. So I went ahead and installed it like so: sudo apt-get install libgeos-dev And it worked. I’m running Ubuntu, so if you’re on Fedora, you should run: sudo yum install geos-devel On MACOS you can run: brew install geos
The trick is to use a combination of the Polygon class methods: from shapely.geometry import Polygon # Create polygon from lists of points x = [0.0, 0.0, 1.0, 1.0, 0.0] y = [0.0, 1.0, 1.0, 0.0, 0.0] poly = Polygon(zip(x,y)) # Extract the point values that define the perimeter of the polygon xx, yy = … Read more