4 from .polygon
import Polygon
10 return "%s(%s)" % (self.__class__.__name__, [p
for p
in self.getVertices()])
13 return self.__class__, (self.getVertices(),)
16 """Iterator over vertices""" 17 vertices = self.getVertices()
20 def __getitem__(self, i):
21 return [pt
for pt
in self][i]
24 return self.getNumEdges()
26 def __contains__(self, point):
27 """point in polygon?""" 28 return self.contains(point)
30 def display(self, xy0=None, frame=1, ctype=None):
31 """Display polygon on existing frame in ds9""" 36 for p1, p2
in self.getEdges():
37 ds9.line((p1 - xy0, p2 - xy0), frame=frame, ctype=ctype)
39 def plot(self, axes=None, **kwargs):
40 """Plot polygon with matplotlib 44 axes : `matplotlib.axes.Axes` 45 Matplotlib axes to use, or None 47 Additional arguments to `matplotlib.axes.Axes.plot` 48 or `matplotlib.axes.Axes.scatter`. 52 axes : `matplotlib.axes.Axes` 53 The axes used to make the plot (same as ``axes``, if provided). 57 import matplotlib.pyplot
as plt
60 for p1, p2
in self.getEdges():
61 x = (p1.getX(), p2.getX())
62 y = (p1.getY(), p2.getY())
63 axes.plot(x, y, **kwargs)
64 vertices = self.getVertices()
65 x = numpy.array([p[0]
for p
in vertices])
66 y = numpy.array([p[1]
for p
in vertices])
67 axes.scatter(x, y, **kwargs)