本文整理汇总了Python中matplotlib.patches.FancyArrowPatch类的典型用法代码示例。如果您正苦于以下问题:Python FancyArrowPatch类的具体用法?Python FancyArrowPatch怎么用?Python FancyArrowPatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FancyArrowPatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
def draw(self, renderer):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
FancyArrowPatch.draw(self, renderer)
示例2: draw
def draw(self, renderer):
#xs3d, ys3d, zs3d = self._verts3d
for coords in self._verts3d:
xs3d, ys3d, zs3d = coords[0], coords[1], coords[2]
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
FancyArrowPatch.draw(self, renderer)
示例3: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this arrow in a subplot. This is the key function that
defines how this arrow graphics primitive is rendered in
matplotlib's library.
EXAMPLES::
This function implicitly ends up rendering this arrow on a matplotlib subplot:
sage: arrow(path=[[(0,1), (2,-1), (4,5)]])
"""
options = self.options()
width = float(options['width'])
head = options.pop('head')
if head == 0: style = '<|-'
elif head == 1: style = '-|>'
elif head == 2: style = '<|-|>'
else: raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both).')
arrowsize = float(options.get('arrowsize',5))
head_width=arrowsize
head_length=arrowsize*2.0
color = to_mpl_color(options['rgbcolor'])
from matplotlib.patches import FancyArrowPatch
from matplotlib.path import Path
bpath = Path(self.vertices, self.codes)
p = FancyArrowPatch(path=bpath,
lw=width, arrowstyle='%s,head_width=%s,head_length=%s'%(style,head_width, head_length),
fc=color, ec=color, linestyle=options['linestyle'])
p.set_zorder(options['zorder'])
p.set_label(options['legend_label'])
subplot.add_patch(p)
return p
示例4: __init__
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)
示例5: draw
def draw(self, renderer):
"""
:param renderer:
"""
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
FancyArrowPatch.draw(self, renderer)
示例6: __init__
def __init__(self,xs,ys,zs,*args,**kwargs):
'''
arguments:
xs: the x coordinates of both sides of the arrow
ys: the y coordinates of both sides of the arrow
zs: the z coordinates of both sides of the arrow
'''
FancyArrowPatch.__init__(self,(0,0),(0,0),*args,**kwargs)
self.verts = xs,ys,zs
示例7: draw
def draw(self, renderer, rasterized=True):
"""
Drawing actually happens here
"""
# Draws only when the dragging finished
if self.leftdown:
return
xs3d, ys3d, zs3d = self._verts3d
for i in xrange(len(xs3d)):
xs, ys, _ = proj3d.proj_transform(xs3d[i], ys3d[i], zs3d[i], renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
self.set_color(self.colors[i])
FancyArrowPatch.draw(self, renderer)
self.leftdown = False
示例8: create_photon_legend
def create_photon_legend(self, legend, orig_handle,
xdescent, ydescent, width, height, fontsize,
trans):
xdata, ydata = get_photon_data2D(width, 0.8*height, 3, 100)
ydata += height*0.3
legline = Line2D(xdata, ydata)
self.update_prop(legline, orig_handle, legend)
legline.set_drawstyle('default')
legline.set_marker("")
legline.set_transform(trans)
yar = FancyArrowPatch((xdata[3],ydata[0]), (xdata[3]+0.3*width, ydata[0]),
mutation_scale=10,
lw=1, arrowstyle="-|>", color='y')
yar.set_transform(trans)
return [legline, yar]
示例9: __init__
def __init__(self, base, xs, ys, zs, colors, *args, **kwargs):
"""
Init
:Params xs: [[x0, x0+dx0], [x1, x1+dx1], ...]
:Params ys: [[y0, y0+dy0], [y1, y1+dy1], ...]
:Params zs: [[z0, z0+dz0], [z1, z1+dz1], ...]
:Params colors: [[R0, G0, B0], [R1, G1, B1], ...]
where R, G, B ranges (0,1)
"""
FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
self.leftdown = False
self.t_click = 0
self._verts3d = xs, ys, zs
self.colors = colors
self.base = base
if base != None:
# To turn the updating off during dragging
base.canvas.mpl_connect('button_press_event', self.on_left_down)
base.canvas.mpl_connect('button_release_event', self.on_left_up)
示例10: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this arrow in a subplot. This is the key function that
defines how this arrow graphics primitive is rendered in
matplotlib's library.
EXAMPLES::
This function implicitly ends up rendering this arrow on a matplotlib subplot:
sage: arrow(path=[[(0,1), (2,-1), (4,5)]])
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.misc import get_matplotlib_linestyle
options = self.options()
width = float(options["width"])
head = options.pop("head")
if head == 0:
style = "<|-"
elif head == 1:
style = "-|>"
elif head == 2:
style = "<|-|>"
else:
raise KeyError("head parameter must be one of 0 (start), 1 (end) or 2 (both).")
arrowsize = float(options.get("arrowsize", 5))
head_width = arrowsize
head_length = arrowsize * 2.0
color = to_mpl_color(options["rgbcolor"])
from matplotlib.patches import FancyArrowPatch
from matplotlib.path import Path
bpath = Path(self.vertices, self.codes)
p = FancyArrowPatch(
path=bpath,
lw=width,
arrowstyle="%s,head_width=%s,head_length=%s" % (style, head_width, head_length),
fc=color,
ec=color,
)
p.set_linestyle(get_matplotlib_linestyle(options["linestyle"], return_type="long"))
p.set_zorder(options["zorder"])
p.set_label(options["legend_label"])
subplot.add_patch(p)
return p
示例11: __init__
def __init__(self, xs, ys, zs, *args, **kwargs):
FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
self._verts3d = xs, ys, zs
示例12: AnnotationBbox
class AnnotationBbox(martist.Artist, _AnnotationBase):
"""
Annotation-like class, but with offsetbox instead of Text.
"""
zorder = 3
def __str__(self):
return "AnnotationBbox(%g,%g)"%(self.xy[0],self.xy[1])
@docstring.dedent_interpd
def __init__(self, offsetbox, xy,
xybox=None,
xycoords='data',
boxcoords=None,
frameon=True, pad=0.4, # BboxPatch
annotation_clip=None,
box_alignment=(0.5, 0.5),
bboxprops=None,
arrowprops=None,
fontsize=None,
**kwargs):
"""
*offsetbox* : OffsetBox instance
*xycoords* : same as Annotation but can be a tuple of two
strings which are interpreted as x and y coordinates.
*boxcoords* : similar to textcoords as Annotation but can be a
tuple of two strings which are interpreted as x and y
coordinates.
*box_alignment* : a tuple of two floats for a vertical and
horizontal alignment of the offset box w.r.t. the *boxcoords*.
The lower-left corner is (0.0) and upper-right corner is (1.1).
other parameters are identical to that of Annotation.
"""
self.offsetbox = offsetbox
self.arrowprops = arrowprops
self.set_fontsize(fontsize)
if arrowprops is not None:
self._arrow_relpos = self.arrowprops.pop("relpos", (0.5, 0.5))
self.arrow_patch = FancyArrowPatch((0, 0), (1,1),
**self.arrowprops)
else:
self._arrow_relpos = None
self.arrow_patch = None
_AnnotationBase.__init__(self,
xy, xytext=xybox,
xycoords=xycoords, textcoords=boxcoords,
annotation_clip=annotation_clip)
martist.Artist.__init__(self, **kwargs)
#self._fw, self._fh = 0., 0. # for alignment
self._box_alignment = box_alignment
# frame
self.patch = FancyBboxPatch(
xy=(0.0, 0.0), width=1., height=1.,
facecolor='w', edgecolor='k',
mutation_scale=self.prop.get_size_in_points(),
snap=True
)
self.patch.set_boxstyle("square",pad=pad)
if bboxprops:
self.patch.set(**bboxprops)
self._drawFrame = frameon
def contains(self,event):
t,tinfo = self.offsetbox.contains(event)
#if self.arrow_patch is not None:
# a,ainfo=self.arrow_patch.contains(event)
# t = t or a
# self.arrow_patch is currently not checked as this can be a line - JJ
return t,tinfo
def get_children(self):
children = [self.offsetbox, self.patch]
if self.arrow_patch:
children.append(self.arrow_patch)
return children
def set_figure(self, fig):
if self.arrow_patch is not None:
self.arrow_patch.set_figure(fig)
self.offsetbox.set_figure(fig)
martist.Artist.set_figure(self, fig)
def set_fontsize(self, s=None):
#.........这里部分代码省略.........
示例13: __init__
def __init__(self, pt1, pt2, *args, **kwargs):
FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
x = [pt1[0, 0], pt2[0, 0]]
y = [pt1[1, 0], pt2[1, 0]]
z = [pt1[2, 0], pt2[2, 0]]
self._verts3d = x, y, z
示例14: AnchoredCompass
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)
示例15: _render_on_subplot
def _render_on_subplot(self, subplot):
r"""
Render this arrow in a subplot. This is the key function that
defines how this arrow graphics primitive is rendered in
matplotlib's library.
EXAMPLES:
This function implicitly ends up rendering this arrow on
a matplotlib subplot::
sage: arrow((0,1), (2,-1))
TESTS:
The length of the ends (shrinkA and shrinkB) should not depend
on the width of the arrow, because Matplotlib already takes
this into account. See :trac:`12836`::
sage: fig = Graphics().matplotlib()
sage: sp = fig.add_subplot(1,1,1)
sage: a = arrow((0,0), (1,1))
sage: b = arrow((0,0), (1,1), width=20)
sage: p1 = a[0]._render_on_subplot(sp)
sage: p2 = b[0]._render_on_subplot(sp)
sage: p1.shrinkA == p2.shrinkA
True
sage: p1.shrinkB == p2.shrinkB
True
Dashed arrows should have solid arrowheads,
:trac:`12852`. This test saves the plot of a dashed arrow to
an EPS file. Within the EPS file, ``stroke`` will be called
twice: once to draw the line, and again to draw the
arrowhead. We check that both calls do not occur while the
dashed line style is enabled::
sage: a = arrow((0,0), (1,1), linestyle='dashed')
sage: filename = tmp_filename(ext='.eps')
sage: a.save(filename=filename)
sage: with open(filename, 'r') as f:
....: contents = f.read().replace('\n', ' ')
sage: two_stroke_pattern = r'setdash.*stroke.*stroke.*setdash'
sage: import re
sage: two_stroke_re = re.compile(two_stroke_pattern)
sage: two_stroke_re.search(contents) is None
True
"""
options = self.options()
head = options.pop('head')
if head == 0: style = '<|-'
elif head == 1: style = '-|>'
elif head == 2: style = '<|-|>'
else: raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both).')
width = float(options['width'])
arrowshorten_end = float(options.get('arrowshorten',0))/2.0
arrowsize = float(options.get('arrowsize',5))
head_width=arrowsize
head_length=arrowsize*2.0
color = to_mpl_color(options['rgbcolor'])
from matplotlib.patches import FancyArrowPatch
p = FancyArrowPatch((self.xtail, self.ytail), (self.xhead, self.yhead),
lw=width, arrowstyle='%s,head_width=%s,head_length=%s'%(style,head_width, head_length),
shrinkA=arrowshorten_end, shrinkB=arrowshorten_end,
fc=color, ec=color, linestyle=options['linestyle'])
p.set_zorder(options['zorder'])
p.set_label(options['legend_label'])
if options['linestyle']!='solid':
# The next few lines work around a design issue in matplotlib. Currently, the specified
# linestyle is used to draw both the path and the arrowhead. If linestyle is 'dashed', this
# looks really odd. This code is from Jae-Joon Lee in response to a post to the matplotlib mailing
# list. See http://sourceforge.net/mailarchive/forum.php?thread_name=CAG%3DuJ%2Bnw2dE05P9TOXTz_zp-mGP3cY801vMH7yt6vgP9_WzU8w%40mail.gmail.com&forum_name=matplotlib-users
import matplotlib.patheffects as pe
class CheckNthSubPath(object):
def __init__(self, patch, n):
"""
creates an callable object that returns True if the provided
path is the n-th path from the patch.
"""
self._patch = patch
self._n = n
def get_paths(self, renderer):
self._patch.set_dpi_cor(renderer.points_to_pixels(1.))
paths, fillables = self._patch.get_path_in_displaycoord()
return paths
def __call__(self, renderer, gc, tpath, affine, rgbFace):
path = self.get_paths(renderer)[self._n]
vert1, code1 = path.vertices, path.codes
import numpy as np
if np.all(vert1 == tpath.vertices) and np.all(code1 == tpath.codes):
return True
else:
return False
#.........这里部分代码省略.........