def plot(self, mode='image', ax=None, **kwargs):
"""Visualize the box on a matplotlib plot.
:param mode: How should the box coordinates and angle be interpreted.
- mode `'image'` corresponds to the situation where x coordinate of the box
denotes the "row of an image" (ie. the Y coordinate of the plot, arranged downwards)
and y coordinate of the box corresponds to the "column of an image",
(ie X coordinate of the plot). In other words, box's x goes downwards and y - rightwards.
- mode `'math'` corresponds to the "mathematics" situation where box's x and y correspond to the X and Y axes of the plot.
:param ax: the matplotlib axis to draw on. If unspecified, the current axis is used.
:param kwargs: arguments passed to the matplotlib's `Polygon` patch object. By default, fill is set to False, color to red and lw to 2.
:return: The created Polygon object.
"""
ax = ax or plt.gca()
poly = self.as_poly()
if mode == 'image':
poly = poly[:,[1,0]]
kwargs.setdefault('fill', False)
kwargs.setdefault('color', 'r')
kwargs.setdefault('lw', 2)
p = patches.Polygon(poly, **kwargs)
ax.add_patch(p)
return p
评论列表
文章目录