1 from ._polygon
import Polygon
7 return "%s(%s)" % (self.__class__.__name__, [p
for p
in self.getVertices()])
11 return self.__class__, (self.getVertices(),)
15 """Iterator over vertices""" 16 vertices = self.getVertices()
21 return [pt
for pt
in self][i]
25 return self.getNumEdges()
29 """point in polygon?""" 30 return self.contains(point)
33 def display(self, xy0=None, frame=1, ctype=None):
34 """Display polygon on existing frame in ds9""" 39 for p1, p2
in self.getEdges():
40 ds9.line((p1 - xy0, p2 - xy0), frame=frame, ctype=ctype)
43 def plot(self, axes=None, **kwargs):
44 """Plot polygon with matplotlib 48 axes : `matplotlib.axes.Axes` 49 Matplotlib axes to use, or None 51 Additional arguments to `matplotlib.axes.Axes.plot` 52 or `matplotlib.axes.Axes.scatter`. 56 axes : `matplotlib.axes.Axes` 57 The axes used to make the plot (same as ``axes``, if provided). 61 import matplotlib.pyplot
as plt
64 for p1, p2
in self.getEdges():
65 x = (p1.getX(), p2.getX())
66 y = (p1.getY(), p2.getY())
67 axes.plot(x, y, **kwargs)
68 vertices = self.getVertices()
69 x = numpy.array([p[0]
for p
in vertices])
70 y = numpy.array([p[1]
for p
in vertices])
71 axes.scatter(x, y, **kwargs)
75 Polygon.__repr__ = __repr__
76 Polygon.__reduce__ = __reduce__
77 Polygon.__iter__ = __iter__
78 Polygon.__getitem__ = __getitem__
79 Polygon.__len__ = __len__
80 Polygon.__contains__ = __contains__
81 Polygon.display = display
def display(self, xy0=None, frame=1, ctype=None)
def __contains__(self, point)
def plot(self, axes=None, kwargs)