A general polygon patch.
| 1231 | |
| 1232 | |
| 1233 | class Polygon(Patch): |
| 1234 | """A general polygon patch.""" |
| 1235 | |
| 1236 | def __str__(self): |
| 1237 | if len(self._path.vertices): |
| 1238 | s = "Polygon%d((%g, %g) ...)" |
| 1239 | return s % (len(self._path.vertices), *self._path.vertices[0]) |
| 1240 | else: |
| 1241 | return "Polygon0()" |
| 1242 | |
| 1243 | @_docstring.interpd |
| 1244 | def __init__(self, xy, *, closed=True, **kwargs): |
| 1245 | """ |
| 1246 | Parameters |
| 1247 | ---------- |
| 1248 | xy : (N, 2) array |
| 1249 | |
| 1250 | closed : bool, default: True |
| 1251 | Whether the polygon is closed (i.e., has identical start and end |
| 1252 | points). |
| 1253 | |
| 1254 | **kwargs |
| 1255 | %(Patch:kwdoc)s |
| 1256 | """ |
| 1257 | super().__init__(**kwargs) |
| 1258 | self._closed = closed |
| 1259 | self.set_xy(xy) |
| 1260 | |
| 1261 | def get_path(self): |
| 1262 | """Get the `.Path` of the polygon.""" |
| 1263 | return self._path |
| 1264 | |
| 1265 | def get_closed(self): |
| 1266 | """Return whether the polygon is closed.""" |
| 1267 | return self._closed |
| 1268 | |
| 1269 | def set_closed(self, closed): |
| 1270 | """ |
| 1271 | Set whether the polygon is closed. |
| 1272 | |
| 1273 | Parameters |
| 1274 | ---------- |
| 1275 | closed : bool |
| 1276 | True if the polygon is closed |
| 1277 | """ |
| 1278 | if self._closed == bool(closed): |
| 1279 | return |
| 1280 | self._closed = bool(closed) |
| 1281 | self.set_xy(self.get_xy()) |
| 1282 | self.stale = True |
| 1283 | |
| 1284 | def get_xy(self): |
| 1285 | """ |
| 1286 | Get the vertices of the path. |
| 1287 | |
| 1288 | Returns |
| 1289 | ------- |
| 1290 | (N, 2) array |
no outgoing calls
searching dependent graphs…