Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from matplotlib import pyplot as plt
- from shapely.geometry import Polygon, Point
- polygon = Polygon([(1, 15), (10, 30), (15, 20), (5, 0), (1, 15)])
- points = [
- Point((5, 17)),
- Point((1, 20)),
- Point((15, 30)),
- Point((9, 10))
- ]
- x, y = polygon.exterior.xy
- fig = plt.figure(1, figsize=(5, 5), dpi=90)
- ax = fig.add_subplot(111)
- ax.plot(x, y)
- for point in points:
- if polygon.contains(point):
- ax.plot([point.x], [point.y], 'go')
- else:
- ax.plot([point.x], [point.y], 'ro')
- ax.set_title('Polygon')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement