本文整理汇总了Python中matplotlib.patches.Polygon.set_transform方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.set_transform方法的具体用法?Python Polygon.set_transform怎么用?Python Polygon.set_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Polygon
的用法示例。
在下文中一共展示了Polygon.set_transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visualize_workspace
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_transform [as 别名]
def visualize_workspace(figure, motion_mdp_edges, WS_d, WS_node_dict, raw_pose, cell_pose, status, show_next):
pyplot.cla()
fig = figure
ax = fig.add_subplot(111)
[l, u, m] = status
#----- draw the robot cell_pose
print 'robot cell pose', cell_pose
xl = cell_pose[0]
yl = cell_pose[1]
dl = cell_pose[2]
if m == 0:
Ecolor = 'green'
elif m == 1:
Ecolor = 'magenta'
elif m == 2:
Ecolor = 'black'
elif m > 2:
Ecolor = 'magenta'
if dl == 'N':
car=[(xl-0.1,yl-0.1), (xl-0.1,yl+0.1), (xl, yl+0.2), (xl+0.1, yl+0.1), (xl+0.1,yl-0.1)]
elif dl == 'E':
car=[(xl-0.1,yl+0.1), (xl+0.1,yl+0.1), (xl+0.2, yl), (xl+0.1, yl-0.1), (xl-0.1,yl-0.1)]
elif dl == 'S':
car=[(xl+0.1,yl+0.1), (xl+0.1,yl-0.1), (xl, yl-0.2), (xl-0.1, yl-0.1), (xl-0.1,yl+0.1)]
elif dl == 'W':
car=[(xl+0.1,yl-0.1), (xl-0.1,yl-0.1), (xl-0.2, yl), (xl-0.1, yl+0.1), (xl+0.1,yl+0.1)]
polygon = Polygon(car, fill = False, facecolor='grey', edgecolor='black', linestyle='dashed', lw=1.5, zorder = 2)
ax.add_patch(polygon)
#----- draw the robot raw_pose
print 'robot raw pose', raw_pose
xl = raw_pose[0]
yl = raw_pose[1]
dl = raw_pose[2]
Ecolor = 'green'
if m == 0:
Ecolor = 'green'
elif m == 1:
Ecolor = 'magenta'
elif m == 2:
Ecolor = 'black'
elif m > 2:
Ecolor = 'magenta'
car=[(xl-0.1,yl-0.1), (xl-0.1,yl+0.1), (xl, yl+0.2), (xl+0.1, yl+0.1), (xl+0.1,yl-0.1)]
polygon2 = Polygon(car, fill = True, facecolor=Ecolor, edgecolor=Ecolor, lw=5, zorder = 2)
ts = ax.transData
coords = ts.transform([xl, yl])
tr = matplotlib.transforms.Affine2D().rotate_deg_around(coords[0], coords[1], dl*180/3.14 -90)
t= ts + tr
polygon2.set_transform(t)
ax.add_patch(polygon2)
#
u = tuple(u)
actstr = r''
for s in u:
actstr += s
ax.text(xl, yl+0.15, r'$%s$' %str(actstr), fontsize = 16, fontweight = 'bold', color='red')
# plot shadow
x = cell_pose[:]
t_x_list = []
for (f_x, t_x) in motion_mdp_edges.iterkeys():
if f_x == tuple(x):
prop = motion_mdp_edges[(f_x, t_x)]
if (show_next and (u in prop.keys())):
t_x_list.append((t_x, prop[u][0]))
#
for new_x in t_x_list:
xl = new_x[0][0]
yl = new_x[0][1]
dl = new_x[0][2]
if dl == 'N':
car=[(xl-0.1,yl-0.1), (xl-0.1,yl+0.1), (xl, yl+0.2), (xl+0.1, yl+0.1), (xl+0.1,yl-0.1)]
elif dl == 'E':
car=[(xl-0.1,yl+0.1), (xl+0.1,yl+0.1), (xl+0.2, yl), (xl+0.1, yl-0.1), (xl-0.1,yl-0.1)]
elif dl == 'S':
car=[(xl+0.1,yl+0.1), (xl+0.1,yl-0.1), (xl, yl-0.2), (xl-0.1, yl-0.1), (xl-0.1,yl+0.1)]
elif dl == 'W':
car=[(xl+0.1,yl-0.1), (xl-0.1,yl-0.1), (xl-0.2, yl), (xl-0.1, yl+0.1), (xl+0.1,yl+0.1)]
polygon = Polygon(car, fill = False, hatch = 'x', edgecolor='grey', lw=5, zorder = 1, alpha=0.5)
ax.add_patch(polygon)
prob = new_x[1]
ax.text(xl, yl, r'$%s$' %str(prob), fontsize = 15, fontweight = 'bold', color='red')
#---------------- draw the workspace
for node, prop in WS_node_dict.iteritems():
if node != (x[0], x[1]):
S = []
P = []
for s, p in prop.iteritems():
S.append(s)
P.append(p)
rdn = random.random()
pc = 0
for k, p in enumerate(P):
pc += p
if pc> rdn:
break
current_s = S[k]
if node == (x[0], x[1]):
current_s = set([l,])
#------
if current_s == set(['base1','base']):
#.........这里部分代码省略.........