SHARE
TWEET

Untitled

a guest Mar 20th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. from matplotlib import pyplot as plt
  4. from shapely.geometry import Polygon, Point
  5.  
  6. polygon = Polygon([(1, 15), (10, 30), (15, 20), (5, 0), (1, 15)])
  7.  
  8. points = [
  9.     Point((5, 17)),
  10.     Point((1, 20)),
  11.     Point((15, 30)),
  12.     Point((9, 10))
  13. ]
  14.  
  15. x, y = polygon.exterior.xy
  16.  
  17. fig = plt.figure(1, figsize=(5, 5), dpi=90)
  18. ax = fig.add_subplot(111)
  19. ax.plot(x, y)
  20. for point in points:
  21.     if polygon.contains(point):
  22.         ax.plot([point.x], [point.y], 'go')
  23.     else:
  24.         ax.plot([point.x], [point.y], 'ro')
  25. ax.set_title('Polygon')
  26. plt.show()
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top