本文整理汇总了Python中matplotlib.patches.Polygon方法的典型用法代码示例。如果您正苦于以下问题:Python patches.Polygon方法的具体用法?Python patches.Polygon怎么用?Python patches.Polygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches
的用法示例。
在下文中一共展示了patches.Polygon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_polygons
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def display_polygons(image, polygons, scores=None, figsize=(16, 16), ax=None, colors=None):
auto_show = False
if ax is None:
_, ax = plt.subplots(1, figsize=figsize)
auto_show = True
if colors is None:
colors = random_colors(len(polygons))
height, width = image.shape[:2]
ax.set_ylim(height + 10, -10)
ax.set_xlim(-10, width + 10)
ax.axis('off')
for i, polygon in enumerate(polygons):
color = colors[i]
polygon = np.reshape(polygon, (-1, 2)) # 转为[n,(x,y)]
patch = patches.Polygon(polygon, facecolor=None, fill=False, color=color)
ax.add_patch(patch)
# 多边形得分
x1, y1 = polygon[0][:]
ax.text(x1, y1 - 1, scores[i] if scores is not None else '',
color='w', size=11, backgroundcolor="none")
ax.imshow(image.astype(np.uint8))
if auto_show:
plt.show()
示例2: box3d_to_lines
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def box3d_to_lines(self, label_id, box3d, calibration, occluded):
"""generate individual bounding box from 3d label"""
label = Label3d.from_box3d(box3d)
edges = label.get_edges_with_visibility(calibration)
box_color = self.get_label_color(label_id)
alpha = 0.5 if occluded else 0.8
lines = []
for edge in edges['dashed']:
lines.append(mpatches.Polygon(edge, linewidth=2 * self.scale,
linestyle=(0, (2, 2)),
edgecolor=box_color,
facecolor='none', fill=False,
alpha=alpha))
for edge in edges['solid']:
lines.append(mpatches.Polygon(edge, linewidth=2 * self.scale,
edgecolor=box_color,
facecolor='none', fill=False,
alpha=alpha))
return lines
示例3: test_plate_detect
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def test_plate_detect():
print("Testing Plate Detect")
file = cfg.DATA_DIR / 'demo' / 'test.jpg'
src = cv2.imread(str(file))
if cfg.VIS and 0:
plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))
plt.show()
results = plate_detect(src)
if cfg.VIS:
for res in results:
print("Plate position: \n", res)
fig = plt.figure(figsize=(10, 10))
ax1 = fig.add_subplot(211)
ax1.imshow(src)
ax1.add_patch(patches.Polygon(res))
ax2 = fig.add_subplot(212)
vis_image = align(src, res)
ax2.imshow(cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB))
plt.show()
示例4: _gen_axes_patch
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def _gen_axes_patch(self):
"""
Returns the patch used to draw the background of the axes. It
is also used as the clipping path for any data elements on the
axes.
In the standard axes, this is a rectangle, but in other
projections it may not be.
.. note::
Intended to be overridden by new projection types.
"""
import matplotlib.patches as mpatches
grid_helper = self.get_grid_helper()
t = grid_helper.get_boundary()
return mpatches.Polygon(t)
示例5: single_color
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def single_color(self, **kwargs):
"""
Creates a single Patch.
+------------+
| |
| |
| 1st |
| |
| |
+------------+
"""
x1, x2 = self.x, self.x+self.dx
y1, y2 = self.y, self.y+self.dy
patch = Polygon([
[x1, y1], # origin
[x2, y1], # to bottom right
[x2, y2], # to top right
[x1, y2], # to top left
[x1, y1]])# to origin
self.patches = [patch]
示例6: onclick_release
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def onclick_release(self, event):
if any([x.in_axes(event) for x in self.button_axes]) or self.selected_poly:
return
if hasattr(self, 'r_x') and hasattr(self, 'r_y') and None not in [self.r_x, self.r_y, event.xdata, event.ydata]:
if np.abs(event.xdata - self.r_x)>10 and np.abs(event.ydata - self.r_y)>10: # 10 pixels limit for rectangle creation
if len(self.points)<4:
self.right_click=True
self.fig.canvas.mpl_disconnect(self.click_id)
self.click_id = None
bbox = [np.min([event.xdata, self.r_x]), np.min([event.ydata, self.r_y]), np.max([event.xdata, self.r_x]), np.max([event.ydata, self.r_y])]
self.r_x = self.r_y = None
self.points = [bbox[0], bbox[1], bbox[0], bbox[3], bbox[2], bbox[3], bbox[2], bbox[1], bbox[0], bbox[1]]
self.p = PatchCollection([Polygon(self.points_to_polygon(), closed=True)], facecolor='red', linewidths=0, alpha=0.4)
self.ax.add_collection(self.p)
self.fig.canvas.draw()
示例7: submit
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def submit(self, event):
if not self.right_click:
print ('Right click before submit is a must!!')
else:
self.text+=self.radio.value_selected+'\n'+'%.2f'%self.find_poly_area()+'\n'+self.print_points()+'\n\n'
self.right_click = False
#print (self.points)
self.lines, self.circles = [], []
self.click_id = fig.canvas.mpl_connect('button_press_event', self.onclick)
self.polys.append(Polygon(self.points_to_polygon(), closed=True, color=np.random.rand(3), alpha=0.4, fill=True))
if self.submit_p:
self.submit_p.remove()
self.submit_p = PatchCollection(self.polys, cmap=matplotlib.cm.jet, alpha=0.4)
self.ax.add_collection(self.submit_p)
self.points = []
示例8: _plot_displacement
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def _plot_displacement(ms):
if not plot:
ms.down
return
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
fig = plt.figure()
ax = fig.gca()
ms.processSources()
ax.imshow(num.flipud(ms.down), aspect='equal',
extent=[0, ms.frame.E.max(), 0, ms.frame.N.max()])
for src in ms.sources:
for seg in src.segments:
p = Polygon(seg.outline(), alpha=.8, fill=False)
ax.add_artist(p)
if isinstance(src, OkadaPath):
nodes = num.array(src.nodes)
ax.scatter(nodes[:, 0], nodes[:, 1], color='r')
plt.show()
fig.clear()
示例9: plot
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
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
示例10: test_path_clipping
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def test_path_clipping():
fig = plt.figure(figsize=(6.0, 6.2))
for i, xy in enumerate([
[(200, 200), (200, 350), (400, 350), (400, 200)],
[(200, 200), (200, 350), (400, 350), (400, 100)],
[(200, 100), (200, 350), (400, 350), (400, 100)],
[(200, 100), (200, 415), (400, 350), (400, 100)],
[(200, 100), (200, 415), (400, 415), (400, 100)],
[(200, 415), (400, 415), (400, 100), (200, 100)],
[(400, 415), (400, 100), (200, 100), (200, 415)]]):
ax = fig.add_subplot(4, 2, i)
bbox = [0, 140, 640, 260]
ax.set_xlim(bbox[0], bbox[0] + bbox[2])
ax.set_ylim(bbox[1], bbox[1] + bbox[3])
ax.add_patch(Polygon(
xy, facecolor='none', edgecolor='red', closed=True))
示例11: draw_gene_simple
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def draw_gene_simple(self, ax, bed, ypos, rgb, edgecolor, linewidth):
"""
draws an interval with direction (if given)
"""
if bed.strand not in ['+', '-']:
ax.add_patch(Rectangle((bed.start, ypos),
bed.end - bed.start, 1,
edgecolor=edgecolor, facecolor=rgb,
linewidth=linewidth))
else:
vertices = self._draw_arrow(bed.start, bed.end, bed.strand, ypos)
ax.add_patch(Polygon(vertices, closed=True, fill=True,
edgecolor=edgecolor,
facecolor=rgb,
linewidth=linewidth))
示例12: __init__
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def __init__(self,xcoord,ycoord,**kwargs):
collections.PatchCollection.__init__(self,[],**kwargs)
tol = 0.02
_xdata1 = np.array([xcoord-tol,xcoord,xcoord+tol])
_ydata1 = np.array([ycoord-tol,ycoord,ycoord-tol])
_xdata2 = np.array([xcoord-tol,xcoord,xcoord-tol])
_ydata2 = np.array([ycoord-tol,ycoord,ycoord+tol])
# Polygons
p1 = patches.Polygon(zip(_xdata1,_ydata1))
p1.set_color("r")
p2 = patches.Polygon(zip(_xdata2,_ydata2))
#print p1,p2
#p2.set_color("g")
# Set data
self.set_paths((p1,p2))
self.set_color("k")
#self.set_marker("-")
#self.set_mfc('r')
#self.set_ms(10)
示例13: _measure
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def _measure(self, qxy, cxy, cid, fc=None, ec=None, gt=None, sc=None):
qx, qy = qxy
cx, cy = cxy
# draw gate box
self._gate(qxy, fc=fc, ec=ec, gt=gt, sc=sc)
# add measure symbol
arc = patches.Arc(xy=(qx, qy - 0.15 * HIG), width=WID * 0.7,
height=HIG * 0.7, theta1=0, theta2=180, fill=False,
ec=self._style.not_gate_lc, linewidth=2, zorder=PORDER_GATE)
self.ax.add_patch(arc)
self.ax.plot([qx, qx + 0.35 * WID], [qy - 0.15 * HIG, qy + 0.20 * HIG],
color=self._style.not_gate_lc, linewidth=2, zorder=PORDER_GATE)
# arrow
self._line(qxy, [cx, cy + 0.35 * WID], lc=self._style.cc, ls=self._style.cline)
arrowhead = patches.Polygon(((cx - 0.20 * WID, cy + 0.35 * WID),
(cx + 0.20 * WID, cy + 0.35 * WID),
(cx, cy)), fc=self._style.cc, ec=None)
self.ax.add_artist(arrowhead)
# target
if self.cregbundle:
self.ax.text(cx + .25, cy + .1, str(cid), ha='left', va='bottom',
fontsize=0.8 * self._style.fs, color=self._style.tc,
clip_on=True, zorder=PORDER_TEXT)
示例14: plot_polygon
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def plot_polygon(ax, x, **kwargs):
ax.add_collection(PatchCollection([patches.Polygon(x, True)], **kwargs))
示例15: plot_polys
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Polygon [as 别名]
def plot_polys(plist,scale=500.0):
fig, ax = plt.subplots()
patches = []
for p in plist:
poly = Polygon(np.array(p)/scale, True)
patches.append(poly)