1 from __future__
import absolute_import, division, print_function
3 from ._polygon
import Polygon
9 return "%s(%s)" % (self.__class__.__name__, [p
for p
in self.getVertices()])
13 return self.__class__, (self.getVertices(),)
17 """Iterator over vertices""" 18 vertices = self.getVertices()
23 return [pt
for pt
in self][i]
27 return self.getNumEdges()
31 """point in polygon?""" 32 return self.contains(point)
35 def display(self, xy0=None, frame=1, ctype=None):
36 """Display polygon on existing frame in ds9""" 41 for p1, p2
in self.getEdges():
42 ds9.line((p1 - xy0, p2 - xy0), frame=frame, ctype=ctype)
45 def plot(self, axes=None, **kwargs):
46 """Plot polygon with matplotlib 50 axes : `matplotlib.axes.Axes` 51 Matplotlib axes to use, or None 53 Additional arguments to `matplotlib.axes.Axes.plot` 54 or `matplotlib.axes.Axes.scatter`. 58 axes : `matplotlib.axes.Axes` 59 The axes used to make the plot (same as ``axes``, if provided). 63 import matplotlib.pyplot
as plt
66 for p1, p2
in self.getEdges():
67 x = (p1.getX(), p2.getX())
68 y = (p1.getY(), p2.getY())
69 axes.plot(x, y, **kwargs)
70 vertices = self.getVertices()
71 x = numpy.array([p[0]
for p
in vertices])
72 y = numpy.array([p[1]
for p
in vertices])
73 axes.scatter(x, y, **kwargs)
77 Polygon.__repr__ = __repr__
78 Polygon.__reduce__ = __reduce__
79 Polygon.__iter__ = __iter__
80 Polygon.__getitem__ = __getitem__
81 Polygon.__len__ = __len__
82 Polygon.__contains__ = __contains__
83 Polygon.display = display
def display(self, xy0=None, frame=1, ctype=None)
def __contains__(self, point)
def plot(self, axes=None, kwargs)