本文整理汇总了Python中matplotlib.patches.FancyArrowPatch.set_positions方法的典型用法代码示例。如果您正苦于以下问题:Python FancyArrowPatch.set_positions方法的具体用法?Python FancyArrowPatch.set_positions怎么用?Python FancyArrowPatch.set_positions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.FancyArrowPatch
的用法示例。
在下文中一共展示了FancyArrowPatch.set_positions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AnchoredCompass
# 需要导入模块: from matplotlib.patches import FancyArrowPatch [as 别名]
# 或者: from matplotlib.patches.FancyArrowPatch import set_positions [as 别名]
class AnchoredCompass(AnchoredOffsetbox):
def __init__(self, ax, transSky2Pix, loc,
arrow_fraction=0.15,
txt1="E", txt2="N",
delta_a1=0, delta_a2=0,
pad=0.1, borderpad=0.5, prop=None, frameon=False,
):
"""
Draw an arrows pointing the directions of E & N
arrow_fraction : length of the arrow as a fraction of axes size
pad, borderpad in fraction of the legend font size (or prop)
"""
self._ax = ax
self._transSky2Pix = transSky2Pix
self._box = AuxTransformBox(ax.transData)
self.delta_a1, self.delta_a2 = delta_a1, delta_a2
self.arrow_fraction = arrow_fraction
kwargs = dict(mutation_scale=11,
shrinkA=0,
shrinkB=5)
self.arrow1 = FancyArrowPatch(posA=(0, 0), posB=(1, 1),
arrowstyle="->",
arrow_transmuter=None,
connectionstyle="arc3",
connector=None,
**kwargs)
self.arrow2 = FancyArrowPatch(posA=(0, 0), posB=(1, 1),
arrowstyle="->",
arrow_transmuter=None,
connectionstyle="arc3",
connector=None,
**kwargs)
x1t, y1t, x2t, y2t = 1, 1, 1, 1
self.txt1 = Text(x1t, y1t, txt1, rotation=0,
rotation_mode="anchor",
va="center", ha="right")
self.txt2 = Text(x2t, y2t, txt2, rotation=0,
rotation_mode="anchor",
va="bottom", ha="center")
self._box.add_artist(self.arrow1)
self._box.add_artist(self.arrow2)
self._box.add_artist(self.txt1)
self._box.add_artist(self.txt2)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=self._box,
prop=prop,
frameon=frameon)
def set_path_effects(self, path_effects):
for a in [self.arrow1, self.arrow2, self.txt1, self.txt2]:
a.set_path_effects(path_effects)
def _update_arrow(self, renderer):
ax = self._ax
x0, y0 = ax.viewLim.x0, ax.viewLim.y0
a1, a2 = estimate_angle(self._transSky2Pix, x0, y0)
a1, a2 = a1+self.delta_a1, a2+self.delta_a2
D = min(ax.viewLim.width, ax.viewLim.height)
d = D * self.arrow_fraction
x1, y1 = x0+d*np.cos(a1/180.*np.pi), y0+d*np.sin(a1/180.*np.pi)
x2, y2 = x0+d*np.cos(a2/180.*np.pi), y0+d*np.sin(a2/180.*np.pi)
self.arrow1.set_positions((x0, y0), (x1, y1))
self.arrow2.set_positions((x0, y0), (x2, y2))
d2 = d
x1t, y1t = x0+d2*np.cos(a1/180.*np.pi), y0+d2*np.sin(a1/180.*np.pi)
x2t, y2t = x0+d2*np.cos(a2/180.*np.pi), y0+d2*np.sin(a2/180.*np.pi)
self.txt1.set_position((x1t, y1t))
self.txt1.set_rotation(a1-180)
self.txt2.set_position((x2t, y2t))
self.txt2.set_rotation(a2-90)
def draw(self, renderer):
self._update_arrow(renderer)
super(AnchoredCompass, self).draw(renderer)
示例2: AnnotationBbox
# 需要导入模块: from matplotlib.patches import FancyArrowPatch [as 别名]
# 或者: from matplotlib.patches.FancyArrowPatch import set_positions [as 别名]
#.........这里部分代码省略.........
return fontsize in points
"""
return self.prop.get_size_in_points()
def update_positions(self, renderer):
"Update the pixel positions of the annotated point and the text."
xy_pixel = self._get_position_xy(renderer)
self._update_position_xybox(renderer, xy_pixel)
mutation_scale = renderer.points_to_pixels(self.get_fontsize())
self.patch.set_mutation_scale(mutation_scale)
if self.arrow_patch:
self.arrow_patch.set_mutation_scale(mutation_scale)
def _update_position_xybox(self, renderer, xy_pixel):
"Update the pixel positions of the annotation text and the arrow patch."
x, y = self.xytext
if isinstance(self.textcoords, tuple):
xcoord, ycoord = self.textcoords
x1, y1 = self._get_xy(renderer, x, y, xcoord)
x2, y2 = self._get_xy(renderer, x, y, ycoord)
ox0, oy0 = x1, y2
else:
ox0, oy0 = self._get_xy(renderer, x, y, self.textcoords)
w, h, xd, yd = self.offsetbox.get_extent(renderer)
_fw, _fh = self._box_alignment
self.offsetbox.set_offset((ox0-_fw*w+xd, oy0-_fh*h+yd))
# update patch position
bbox = self.offsetbox.get_window_extent(renderer)
#self.offsetbox.set_offset((ox0-_fw*w, oy0-_fh*h))
self.patch.set_bounds(bbox.x0, bbox.y0,
bbox.width, bbox.height)
x, y = xy_pixel
ox1, oy1 = x, y
if self.arrowprops:
x0, y0 = x, y
d = self.arrowprops.copy()
# Use FancyArrowPatch if self.arrowprops has "arrowstyle" key.
# adjust the starting point of the arrow relative to
# the textbox.
# TODO : Rotation needs to be accounted.
relpos = self._arrow_relpos
ox0 = bbox.x0 + bbox.width * relpos[0]
oy0 = bbox.y0 + bbox.height * relpos[1]
# The arrow will be drawn from (ox0, oy0) to (ox1,
# oy1). It will be first clipped by patchA and patchB.
# Then it will be shrinked by shirnkA and shrinkB
# (in points). If patch A is not set, self.bbox_patch
# is used.
self.arrow_patch.set_positions((ox0, oy0), (ox1,oy1))
fs = self.prop.get_size_in_points()
mutation_scale = d.pop("mutation_scale", fs)
mutation_scale = renderer.points_to_pixels(mutation_scale)
self.arrow_patch.set_mutation_scale(mutation_scale)
patchA = d.pop("patchA", self.patch)
self.arrow_patch.set_patchA(patchA)
def draw(self, renderer):
"""
Draw the :class:`Annotation` object to the given *renderer*.
"""
if renderer is not None:
self._renderer = renderer
if not self.get_visible(): return
xy_pixel = self._get_position_xy(renderer)
if not self._check_xy(renderer, xy_pixel):
return
self.update_positions(renderer)
if self.arrow_patch is not None:
if self.arrow_patch.figure is None and self.figure is not None:
self.arrow_patch.figure = self.figure
self.arrow_patch.draw(renderer)
if self._drawFrame:
self.patch.draw(renderer)
self.offsetbox.draw(renderer)
示例3: EnvironmentReader
# 需要导入模块: from matplotlib.patches import FancyArrowPatch [as 别名]
# 或者: from matplotlib.patches.FancyArrowPatch import set_positions [as 别名]
#.........这里部分代码省略.........
cur_j = 1+self.cur_i+ np.nonzero(self.vl['Iter num'][self.cur_i:] == self.cur_iter)[0][-1]
except:
# There is no iteration with that value
self.cur_iter += 1
return [np.NAN, np.NAN, np.NAN, np.NAN]
cur_x = self.vl['xs'][self.cur_i:cur_j]
cur_y = self.vl['ys'][self.cur_i:cur_j]
cur_vx = self.vl['vxs'][self.cur_i:cur_j]
cur_vy = self.vl['vys'][self.cur_i:cur_j]
self.cur_iter += 1
self.cur_i = cur_j
return (cur_x, cur_y, cur_vx, cur_vy)
def draw_HMM_sectors(self):
return
for i in range(self.HMM.cll_p_sd):
curx = self.HMM.xrange[0]+i*self.HMM.dx
cury = self.HMM.yrange[0]+i*self.HMM.dy
self.ax_env.plot([curx,curx],[0,self.maxy],'k')
self.ax_env.plot([0,self.maxx],[cury,cury], 'k')
def draw_plc_flds(self):
return
clrs = ['b','g']
legend_widgets = []
for i, plc_flds in zip(range(len(self.WR.contexts)),self.WR.contexts.values()):
added = False
for plc_fld in plc_flds:
circ = Circle([plc_fld.x,plc_fld.y], plc_fld.r, color=clrs[i])
self.ax_env.add_patch(circ)
if not added:
legend_widgets.append(circ)
added=True
self.ax.legend(legend_widgets, ('counterclockwise','clockwise'),'lower right')
def draw(self, xs,ys,vxs,vys):
''' Display the environment data to the window.
The environment data are inputs. '''
if np.any(np.isnan(xs)):
return
# Display how far along in the animation we are
self.iters.set_text('%i/%i'%(self.cur_iter,self.max_iter))
# Begin the drawing process
self.canvas.restore_region(self.background)
# Calculate and draw rat's physical position
x = xs[-1]; y=ys[-1]; vx=vxs[-1]; vy=vys[-1]
self.x_hist.extend(xs)
self.y_hist.extend(ys)
self.pos.set_data(self.x_hist,self.y_hist)
# Adjust velocity vector
if vx != 0 or vy != 0:
self.vel.set_positions([x, y], [x+vx,y+vy])
# Adjust radius line
#self.radius.set_data([self.cntr_x,x],[self.cntr_y,y])
# Calculate physical orientation, display it, and compare with
# virmenLog's orientatino assessment
cur_orientation = self.is_clockwise(x,y,vx,vy)
if cur_orientation == 1:
self.clockcounter.set_text('Clockwise')
else:
self.clockcounter.set_text('Counterclockwise')
# Adjust the location of the rat's chased target
target_x = self.vl['txs'][self.cur_i]
target_y = self.vl['tys'][self.cur_i]
self.target.center = [target_x,target_y]
# Make a context prediction
try:
self._make_prediction(self.is_clockwise(x,y,vx,vy))
except:
pass
#logging.warning('Make prediction failed.')
# Update the drawing window
for itm in [self.pos, self.vel, #self.radius,
self.clockcounter,self.iters,
self.predicted_counter, self.target]:
self.ax.draw_artist(itm)
self.canvas.blit(self.ax.bbox)
def is_clockwise(self,x,y,vx,vy):
''' Determines if motion is clockwise around the center
of the room, which is [0, MAXX] x [0, MAXY]
Output mapped to {-1,1} to conform with vl['Task'] labels.'''
cross_prod = (x-self.cntr_x)*vy - (y-self.cntr_y)*vx
clockwise = 2*(cross_prod>0)-1
return clockwise