本文整理匯總了Python中matplotlib.patches.FancyBboxPatch方法的典型用法代碼示例。如果您正苦於以下問題:Python patches.FancyBboxPatch方法的具體用法?Python patches.FancyBboxPatch怎麽用?Python patches.FancyBboxPatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.patches
的用法示例。
在下文中一共展示了patches.FancyBboxPatch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test1
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def test1(ax):
# a fancy box with round corners. pad=0.1
p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
abs(bb.width), abs(bb.height),
boxstyle="round,pad=0.1",
fc=(1., .8, 1.),
ec=(1., 0.5, 1.))
ax.add_patch(p_fancy)
ax.text(0.1, 0.8,
r' boxstyle="round,pad=0.1"',
size=10, transform=ax.transAxes)
# draws control points for the fancy box.
# l = p_fancy.get_path().vertices
# ax.plot(l[:,0], l[:,1], ".")
# draw the original bbox in black
draw_bbox(ax, bb)
示例2: test3
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def test3(ax):
# mutation_scale determine overall scale of the mutation,
# i.e. both pad and rounding_size is scaled according to this
# value.
p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
abs(bb.width), abs(bb.height),
boxstyle="round,pad=0.1",
mutation_scale=2.,
fc=(1., .8, 1.),
ec=(1., 0.5, 1.))
ax.add_patch(p_fancy)
ax.text(0.1, 0.8,
' boxstyle="round,pad=0.1"\n mutation_scale=2',
size=10, transform=ax.transAxes)
# draws control points for the fancy box.
# l = p_fancy.get_path().vertices
# ax.plot(l[:,0], l[:,1], ".")
draw_bbox(ax, bb)
示例3: __init__
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def __init__(self, child, pad=None, draw_frame=False, patch_attrs=None):
"""
*pad* : boundary pad
.. note::
*pad* need to given in points and will be
scale with the renderer dpi, while *width* and *height*
need to be in pixels.
"""
super(PaddedBox, self).__init__()
self.pad = pad
self._children = [child]
self.patch = FancyBboxPatch(
xy=(0.0, 0.0), width=1., height=1.,
facecolor='w', edgecolor='k',
mutation_scale=1, # self.prop.get_size_in_points(),
snap=True
)
self.patch.set_boxstyle("square", pad=0)
if patch_attrs is not None:
self.patch.update(patch_attrs)
self._drawFrame = draw_frame
示例4: set_bbox
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def set_bbox(self, rectprops):
"""
Draw a bounding box around self. rectprops are any settable
properties for a rectangle, eg facecolor='red', alpha=0.5.
t.set_bbox(dict(facecolor='red', alpha=0.5))
If rectprops has "boxstyle" key. A FancyBboxPatch
is initialized with rectprops and will be drawn. The mutation
scale of the FancyBboxPath is set to the fontsize.
ACCEPTS: rectangle prop dict
"""
# The self._bbox_patch object is created only if rectprops has
# boxstyle key. Otherwise, self._bbox will be set to the
# rectprops and the bbox will be drawn using bbox_artist
# function. This is to keep the backward compatibility.
if rectprops is not None and "boxstyle" in rectprops:
props = rectprops.copy()
boxstyle = props.pop("boxstyle")
bbox_transmuter = props.pop("bbox_transmuter", None)
self._bbox_patch = FancyBboxPatch(
(0., 0.),
1., 1.,
boxstyle=boxstyle,
bbox_transmuter=bbox_transmuter,
transform=mtransforms.IdentityTransform(),
**props)
self._bbox = None
else:
self._bbox_patch = None
self._bbox = rectprops
示例5: get_bbox_patch
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def get_bbox_patch(self):
"""
Return the bbox Patch object. Returns None if the the
FancyBboxPatch is not made.
"""
return self._bbox_patch
示例6: height
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def height(self):
shape = self.brush.style[1]
if isinstance(self.obj, plt.Circle):
return self.obj.radius * 2
elif isinstance(self.obj, plt.Rectangle):
return self.obj.get_height()
elif isinstance(self.obj, patches.FancyBboxPatch):
return self.obj.get_height() + 2*self.obj.get_boxstyle().pad
elif isinstance(self.obj, (plt.Polygon, patches.PathPatch)):
y = self.path[:,1]
return y.max() - y.min()
else:
raise
示例7: width
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def width(self):
shape = self.brush.style[1]
if isinstance(self.obj, plt.Circle):
return self.obj.radius * 2
elif isinstance(self.obj, plt.Rectangle):
return self.obj.get_width()
elif isinstance(self.obj, patches.FancyBboxPatch):
return self.obj.get_width() + 2*self.obj.get_boxstyle().pad
elif isinstance(self.obj, (plt.Polygon, patches.PathPatch)):
x = self.path[:,0]
return x.max() - x.min()
else:
raise
示例8: rectangle
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def rectangle(xy, size, angle, roundness, **kwargs):
'''width is relative width with respect to height.'''
if np.ndim(size) == 0:
size = (size, size)
width, height = 2*size[0], 2*size[1]
xy_ = xy[0] - width / 2., xy[1] - height / 2.
if roundness!=0:
pad = roundness
c = patches.FancyBboxPatch(xy_+np.array([pad,pad]), width-pad*2, height-pad*2,
boxstyle=patches.BoxStyle("Round", pad=pad), **_fix(kwargs))
else:
c = patches.Rectangle(xy_, width, height, **_fix(kwargs))
return [c]
########################## Derived types #############################
示例9: draw_features
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def draw_features(features, ax=None, alpha=0.65, width=2e-5, **kwargs):
if ax is None:
fig, ax = plt.subplots(1)
ellipses = []
kwargs.setdefault("lw", 0.05)
lw = kwargs.get("linewidth", kwargs.get("lw"))
for feat in features:
if feat is None:
continue
center = (feat.end_time + feat.start_time) / 2.
height = feat.end_time - feat.start_time
center_mz = feat.mz
mz_width = center_mz * width
ellipses.append(
FancyBboxPatch((feat.mz - mz_width / 4., center - height / 2.), width=mz_width / 2., height=height,
boxstyle=mpatches.BoxStyle.Round(pad=mz_width / 2.)))
for ell in ellipses:
ell.set_alpha(alpha)
ell.set_facecolor("blue")
ell.set_edgecolor("blue")
ell.set_linewidth(lw)
ax.add_artist(ell)
ax.set_xlim(
min(features, key=lambda x: x.mz if x is not None else float('inf')).mz - 1,
max(features, key=lambda x: x.mz if x is not None else -float('inf')).mz + 1)
ax.set_ylim(
min(features, key=lambda x: x.start_time if x is not None else float('inf')).start_time - 1,
max(features, key=lambda x: x.end_time if x is not None else -float('inf')).end_time + 1)
return ax
示例10: set_bbox
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def set_bbox(self, rectprops):
"""
Draw a bounding box around self. rectprops are any settable
properties for a rectangle, e.g., facecolor='red', alpha=0.5.
t.set_bbox(dict(facecolor='red', alpha=0.5))
If rectprops has "boxstyle" key. A FancyBboxPatch
is initialized with rectprops and will be drawn. The mutation
scale of the FancyBboxPath is set to the fontsize.
ACCEPTS: rectangle prop dict
"""
# The self._bbox_patch object is created only if rectprops has
# boxstyle key. Otherwise, self._bbox will be set to the
# rectprops and the bbox will be drawn using bbox_artist
# function. This is to keep the backward compatibility.
if rectprops is not None and "boxstyle" in rectprops:
props = rectprops.copy()
boxstyle = props.pop("boxstyle")
bbox_transmuter = props.pop("bbox_transmuter", None)
self._bbox_patch = FancyBboxPatch(
(0., 0.),
1., 1.,
boxstyle=boxstyle,
bbox_transmuter=bbox_transmuter,
transform=mtransforms.IdentityTransform(),
**props)
self._bbox = None
else:
self._bbox_patch = None
self._bbox = rectprops
self._update_clip_properties()
示例11: __init__
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def __init__(self, child, pad=None, draw_frame=False, patch_attrs=None):
"""
*pad* : boundary pad
.. note::
*pad* need to given in points and will be
scale with the renderer dpi, while *width* and *height*
need to be in pixels.
"""
super().__init__()
self.pad = pad
self._children = [child]
self.patch = FancyBboxPatch(
xy=(0.0, 0.0), width=1., height=1.,
facecolor='w', edgecolor='k',
mutation_scale=1, # self.prop.get_size_in_points(),
snap=True
)
self.patch.set_boxstyle("square", pad=0)
if patch_attrs is not None:
self.patch.update(patch_attrs)
self._drawFrame = draw_frame
示例12: draw_bbox
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def draw_bbox(ax, bb):
# boxstyle=square with pad=0, i.e. bbox itself.
p_bbox = FancyBboxPatch((bb.xmin, bb.ymin),
abs(bb.width), abs(bb.height),
boxstyle="square,pad=0.",
ec="k", fc="none", zorder=10.,
)
ax.add_patch(p_bbox)
示例13: test2
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def test2(ax):
# bbox=round has two optional argument. pad and rounding_size.
# They can be set during the initialization.
p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
abs(bb.width), abs(bb.height),
boxstyle="round,pad=0.1",
fc=(1., .8, 1.),
ec=(1., 0.5, 1.))
ax.add_patch(p_fancy)
# boxstyle and its argument can be later modified with
# set_boxstyle method. Note that the old attributes are simply
# forgotten even if the boxstyle name is same.
p_fancy.set_boxstyle("round,pad=0.1, rounding_size=0.2")
# or
# p_fancy.set_boxstyle("round", pad=0.1, rounding_size=0.2)
ax.text(0.1, 0.8,
' boxstyle="round,pad=0.1\n rounding_size=0.2"',
size=10, transform=ax.transAxes)
# draws control points for the fancy box.
# l = p_fancy.get_path().vertices
# ax.plot(l[:,0], l[:,1], ".")
draw_bbox(ax, bb)
示例14: test4
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def test4(ax):
# When the aspect ratio of the axes is not 1, the fancy box may
# not be what you expected (green)
p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
abs(bb.width), abs(bb.height),
boxstyle="round,pad=0.2",
fc="none",
ec=(0., .5, 0.), zorder=4)
ax.add_patch(p_fancy)
# You can compensate this by setting the mutation_aspect (pink).
p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
abs(bb.width), abs(bb.height),
boxstyle="round,pad=0.3",
mutation_aspect=.5,
fc=(1., 0.8, 1.),
ec=(1., 0.5, 1.))
ax.add_patch(p_fancy)
ax.text(0.1, 0.8,
' boxstyle="round,pad=0.3"\n mutation_aspect=.5',
size=10, transform=ax.transAxes)
draw_bbox(ax, bb)
示例15: __init__
# 需要導入模塊: from matplotlib import patches [as 別名]
# 或者: from matplotlib.patches import FancyBboxPatch [as 別名]
def __init__(self,
x=0, y=0, text='',
color=None, # defaults to rc params
verticalalignment='baseline',
horizontalalignment='left',
multialignment=None,
fontproperties=None, # defaults to FontProperties()
rotation=None,
linespacing=None,
rotation_mode=None,
**kwargs
):
"""
Create a :class:`~matplotlib.text.Text` instance at *x*, *y*
with string *text*.
Valid kwargs are
%(Text)s
"""
Artist.__init__(self)
self._x, self._y = x, y
if color is None:
color = rcParams['text.color']
if fontproperties is None:
fontproperties = FontProperties()
elif is_string_like(fontproperties):
fontproperties = FontProperties(fontproperties)
self.set_text(text)
self.set_color(color)
self._verticalalignment = verticalalignment
self._horizontalalignment = horizontalalignment
self._multialignment = multialignment
self._rotation = rotation
self._fontproperties = fontproperties
self._bbox = None
self._bbox_patch = None # a FancyBboxPatch instance
self._renderer = None
if linespacing is None:
linespacing = 1.2 # Maybe use rcParam later.
self._linespacing = linespacing
self.set_rotation_mode(rotation_mode)
self.update(kwargs)
#self.set_bbox(dict(pad=0))