本文整理汇总了Python中matplotlib.offsetbox.AuxTransformBox类的典型用法代码示例。如果您正苦于以下问题:Python AuxTransformBox类的具体用法?Python AuxTransformBox怎么用?Python AuxTransformBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuxTransformBox类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: AnchoredSizeBar
class AnchoredSizeBar(AnchoredOffsetbox):
def __init__(self, transform, size, label, loc,
pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True):
"""
Draw a horizontal bar with the size in data coordinate of the give axes.
A label will be drawn underneath (center-aligned).
pad, borderpad in fraction of the legend font size (or prop)
sep in points.
loc:
'upper right' : 1,
'upper left' : 2,
'lower left' : 3,
'lower right' : 4,
'right' : 5,
'center left' : 6,
'center right' : 7,
'lower center' : 8,
'upper center' : 9,
'center' : 10
"""
self.size_bar = AuxTransformBox(transform)
self.size_bar.add_artist(Rectangle((0, 0), size, 0, fc='none', color='white', lw=3))
self.txt_label = TextArea(label, dict(color='white', size='x-large', weight='normal'),
minimumdescent=False)
self._box = VPacker(children=[self.size_bar, self.txt_label],
align="center",
pad=0, sep=sep)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=self._box,
prop=prop,
frameon=frameon)
开发者ID:dmitryduev,项目名称:dataqt,代码行数:35,代码来源:dataqt.py
示例2: ScaleBar
class ScaleBar(AnchoredOffsetbox):
def __init__(self, ax, label, bar_length, **props):
'''
Draw a horizontal bar with the size in data coordinate of the give axes.
A label will be drawn above (center-aligned).
'''
label_size = props['label_size'] if 'label_size' in props else \
rcParams.get('scalebar.label_size', 16)
label_family = props['label_family'] if 'label_family' in props else \
rcParams.get('scalebar.label_family', 'sans-serif')
label_color = props['label_color'] if 'label_color' in props else \
rcParams.get('scalebar.label_color', 'black')
location = props['location'] if 'location' in props else \
rcParams.get('scalebar.location', 4)
padding = props['padding'] if 'padding' in props else \
rcParams.get('scalebar.padding', 0.5)
sep = props['sep'] if 'sep' in props else \
rcParams.get('scalebar.sep', 2)
bar_color = props['bar_color'] if 'bar_color' in props else \
rcParams.get('scalebar.bar_color', 'black')
bar_width = props['bar_width'] if 'bar_width' in props else \
rcParams.get('scalebar.bar_width', 0.1)
bar_length = props['bar_length'] if 'bar_length' in props else \
rcParams.get('scalebar.bar_length', 0.8)
frameon = False
prop = None
self.scale_bar = AuxTransformBox(ax.transData)
rect = mpatches.Rectangle((0, 0),
bar_length, bar_width,
linewidth=0, edgecolor=None,
facecolor=bar_color)
self.scale_bar.add_artist(rect)
textprops = {'size': label_size}
self.txt_label = TextArea(label, textprops=textprops, minimumdescent=False)
self._box = VPacker(children=[self.txt_label, self.scale_bar],
align="center",
pad=0, sep=sep)
AnchoredOffsetbox.__init__(self, location, pad=padding, borderpad=0,
child=self._box,
prop=prop,
frameon=frameon)
开发者ID:ngroup,项目名称:py_figure_template,代码行数:50,代码来源:scalebar.py
示例3: create_rect_patch
def create_rect_patch(ec="#000000", fc=None):
_box = AuxTransformBox(transforms.IdentityTransform())
rect = FancyBboxPatch(
xy=(0, 0),
width=0.02,
height=0.02,
boxstyle='square',
ec=ec,
fc=fc,
mutation_scale=14, # font size
transform=trans,
alpha=1.0 if (ec is not None or fc is not None) else 0.0
)
_box.add_artist(rect)
return _box
开发者ID:claudioquaglia,项目名称:PyXRD,代码行数:15,代码来源:plotters.py
示例4: __init__
def __init__(self, transform, sizex=0, sizey=0, labelx=None, labely=None,
loc=3, pad=0.1, borderpad=0.1, sep=2, prop=None, **kwargs):
"""
Draw a horizontal and/or vertical bar with the size in data coordinate
of the give axes. A label will be drawn underneath (center-aligned).
- transform : the coordinate frame (typically axes.transData)
- sizex,sizey : width of x,y bar, in data units. 0 to omit
- labelx,labely : labels for x,y bars; None to omit
- loc : position in containing axes
- pad, borderpad : padding, in fraction of legend font size (or prop)
- sep : separation between labels and bars in points.
- **kwargs : additional arguments passed to base class constructor
"""
from matplotlib.patches import Rectangle
from matplotlib.offsetbox import AuxTransformBox, VPacker, HPacker
from matplotlib.offsetbox import TextArea, DrawingArea
bars = AuxTransformBox(transform)
if sizex:
bars.add_artist(Rectangle((0, 0), sizex, 0, fc="none"))
if sizey:
bars.add_artist(Rectangle((0, 0), 0, sizey, fc="none"))
if sizex and labelx:
bars = VPacker(children=[bars, TextArea(labelx,
minimumdescent=False)],
align="center", pad=0, sep=sep)
if sizey and labely:
bars = HPacker(children=[TextArea(labely), bars],
align="center", pad=0, sep=sep)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=bars, prop=prop, frameon=False,
**kwargs)
开发者ID:girishhalcyon,项目名称:WesThesis2016,代码行数:33,代码来源:gen_sim.py
示例5: __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)
开发者ID:dreadtoad,项目名称:pywcsgrid2,代码行数:57,代码来源:aux_artists.py
示例6: __init__
def __init__(self, transform, sizex=0, sizey=0, labelx=None, labely=None,
loc=4, pad=0.1, borderpad=0.1, sep=2, prop=None, fontsize='medium', **kwargs):
"""
Modified, draws a horizontal and/or vertical bar with the size in data coordinate
of the give axes. A label will be drawn underneath (center-aligned).
Parameters
----------
transform : the coordinate frame (typically axes.transData)
sizex, sizey : width of x,y bar, in data units. 0 to omit
labelx, labely : labels for x,y bars; None to omit
loc : position in containing axes
pad, borderpad : padding, in fraction of the legend font size (or prop)
sep : separation between labels and bars in points.
**kwargs : additional arguments passed to base class constructor
Notes
-----
Adapted from mpl_toolkits.axes_grid2
"""
from matplotlib.lines import Line2D
from matplotlib.text import Text
from matplotlib.offsetbox import AuxTransformBox
bars = AuxTransformBox(transform)
inv = transform.inverted()
pixelxy = inv.transform((1, 1)) - inv.transform((0, 0))
if sizex:
barx = Line2D([sizex, 0], [0, 0], transform=transform, color='k')
bars.add_artist(barx)
if sizey:
bary = Line2D([0, 0], [0, sizey], transform=transform, color='k')
bars.add_artist(bary)
if sizex and labelx:
textx = Text(text=labelx, x=sizex/2.0, y=-5*pixelxy[1], ha='center', va='top', size=fontsize)
bars.add_artist(textx)
if sizey and labely:
texty = Text(text=labely, rotation='vertical', y=sizey/2.0, x=-2*pixelxy[0],
va='center', ha='right', size=fontsize)
bars.add_artist(texty)
AnchoredOffsetbox.__init__(self, loc=loc, pad=pad, borderpad=borderpad,
child=bars, prop=prop, frameon=False, **kwargs)
开发者ID:emirvine,项目名称:scalebar,代码行数:47,代码来源:scalebar.py
示例7: __init__
def __init__(
self,
transform,
sizex=0,
sizey=0,
labelx=None,
labely=None,
loc=4,
pad=0.1,
borderpad=0.1,
sep=2,
prop=None,
label_fontsize=label_fontsize,
color="k",
**kwargs
):
"""
Draw a horizontal and/or vertical bar with the size in data coordinate
of the give axes. A label will be drawn underneath (center-aligned).
- transform : the coordinate frame (typically axes.transData)
- sizex,sizey : width of x,y bar, in data units. 0 to omit
- labelx,labely : labels for x,y bars; None to omit
- loc : position in containing axes
- pad, borderpad : padding, in fraction of the legend font size (or prop)
- sep : separation between labels and bars in points.
- **kwargs : additional arguments passed to base class constructor
"""
from matplotlib.patches import Rectangle
from matplotlib.offsetbox import AuxTransformBox, VPacker, HPacker, TextArea, DrawingArea
bars = AuxTransformBox(transform)
if sizex:
bars.add_artist(Rectangle((0, 0), sizex, 0, fc="none", linewidth=axes_linewidth, color=color))
if sizey:
bars.add_artist(Rectangle((0, 0), 0, sizey, fc="none", linewidth=axes_linewidth, color=color))
if sizex and labelx:
textareax = TextArea(labelx, minimumdescent=False, textprops=dict(size=label_fontsize, color=color))
bars = VPacker(children=[bars, textareax], align="center", pad=0, sep=sep)
if sizey and labely:
## VPack a padstr below the rotated labely, else label y goes below the scale bar
## Just adding spaces before labely doesn't work!
padstr = "\n " * len(labely)
textareafiller = TextArea(padstr, textprops=dict(size=label_fontsize / 3.0))
textareay = TextArea(labely, textprops=dict(size=label_fontsize, rotation="vertical", color=color))
## filler / pad string VPack-ed below labely
textareayoffset = VPacker(children=[textareay, textareafiller], align="center", pad=0, sep=sep)
## now HPack this padded labely to the bars
bars = HPacker(children=[textareayoffset, bars], align="top", pad=0, sep=sep)
AnchoredOffsetbox.__init__(
self, loc, pad=pad, borderpad=borderpad, child=bars, prop=prop, frameon=False, **kwargs
)
开发者ID:adityagilra,项目名称:olfactory-bulb,代码行数:54,代码来源:data_utils.py
示例8: __init__
def __init__(self, transform, fig_transform,
sizex=0, sizey=0, labelx=None, labely=None, loc=4,
xbar_width = 2, ybar_width = 2,
pad=3, borderpad=0.1, xsep=3, ysep = 3, prop=None, textprops={'size':10}, **kwargs):
"""
Draw a horizontal and/or vertical bar with the size in data coordinate
of the give axes. A label will be drawn underneath (center-aligned).
- transform : the coordinate frame (typically axes.transData)
- sizex,sizey : width of x,y bar, in data units. 0 to omit
- labelx,labely : labels for x,y bars; None to omit
- loc : position in containing axes
- pad, borderpad : padding, in fraction of the legend font size (or prop)
- sep : separation between labels and bars in points.
- **kwargs : additional arguments passed to base class constructor
"""
from matplotlib.patches import Rectangle
from matplotlib.offsetbox import AuxTransformBox, VPacker, HPacker, TextArea, DrawingArea
# new shit
# try splitting the transform into X and Y so that
import matplotlib.transforms as transforms
xtransform = transforms.blended_transform_factory(transform, fig_transform)
ytransform = transforms.blended_transform_factory(fig_transform, transform)
# end new shit
# bars = AuxTransformBox(xtransform)
# if sizey:
# bars.add_artist(Rectangle((0,0), ybar_width, sizey,
# fc="Black"))
# if sizex:
# bars.add_artist(Rectangle((0,0), sizex, xbar_width,
# fc="Black"))
ybar_width /= 72.
xbar_width /= 72.
if sizey:
ybar = AuxTransformBox(ytransform)
ybar.add_artist(Rectangle((0,0), ybar_width, sizey, fc="Black"))
bars = ybar
if sizex:
xbar = AuxTransformBox(xtransform)
xbar.add_artist(Rectangle((0,0), sizex, xbar_width, fc="Black"))
bars = xbar
if sizex and sizey:
bars = VPacker(children=[ybar, xbar], pad = 10, sep=ysep)
if sizex and labelx:
bars = VPacker(children=[bars, TextArea(labelx,
minimumdescent=False,
textprops = textprops)],
align="center", pad=0, sep=-3)
if sizey and labely:
bars = HPacker(children=[TextArea(labely,
textprops = textprops), bars],
align="center", pad=0, sep=xsep)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=bars, prop=prop, frameon=False, **kwargs)
开发者ID:matthewperkins,项目名称:plotting,代码行数:58,代码来源:mp_scale_bars.py
示例9: __init__
def __init__(self, transform, sizex=0, sizey=0, labelx=None, labely=None, loc=4,
pad=0.1, borderpad=0.1, sep=2, linewidth=3, prop=None, fontprops={},
**kwargs):
"""
Args:
- transform : the coordinate frame (typically axes.transData)
- sizex,sizey : width of x,y bar, in data units. 0 to omit
- labelx,labely : labels for x,y bars; None to omit
- loc : position in containing axes, see matplotlib.offsetbox.AnchoredOffsetbox for docs
- pad, borderpad : padding, in fraction of the legend font size (or prop)
- sep : separation between labels and bars in points.
- fontprops: dict specifying text label properties, https://matplotlib.org/users/text_props.html
- **kwargs : additional arguments passed to base class constructor
"""
from matplotlib.patches import Rectangle
from matplotlib.lines import Line2D
from matplotlib.offsetbox import AuxTransformBox, VPacker, HPacker, TextArea, DrawingArea, OffsetBox
fontprops.update({'fontsize': 8}) # need fontprops defaults here, otherwise overwritten on change if in fn defn
bars = AuxTransformBox(transform)
bars.add_artist(Line2D((0,0,sizex),(sizey,0,0), lw=linewidth,
color='k', solid_capstyle='butt', solid_joinstyle='miter'))
# Note: this packs the y label and both bars together into a box, then packs the x label below the box, so the
# x label is slightly off center of the x bar. This can cause some small alignment problems, but fixing it requires knowledge
# of matplotlib offsetboxes, auxtransformboxes, and transforms that I don't have.
if sizey and labely:
bars = HPacker(children=[TextArea(labely.strip(), textprops=fontprops), bars],
align="center", pad=0, sep=sep)
if sizex and labelx:
bars = VPacker(children=[bars, TextArea(labelx.strip(), minimumdescent=False, textprops=fontprops)],
align="center", pad=0, sep=sep)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=bars, prop=prop, frameon=False, **kwargs)
开发者ID:histed,项目名称:PyToolsMH,代码行数:38,代码来源:plotting.py
示例10: sm_plot
def sm_plot(self,sm_map,ars=None):
""" Plot images as SM does """
map_fig = plt.figure()
sm_map.plot()
sm_map.draw_limb()
sm_map.draw_grid(grid_spacing=10)#grid=False, colorbar=False)
ax=plt.gca()
arr = np.ones(256).reshape(1,256)
if ars is not None:
for ar_number,pos in ars.items():
text_path = TextPath((0,0),ar_number)
text_patch = PathClippedImagePatch(text_path, arr, ec="none",
transform=IdentityTransform())
shadow1 = mpatches.Shadow(text_patch,1,-1,props=dict(fc="none", ec="0.6", lw=3))
offsetbox = AuxTransformBox(IdentityTransform())
offsetbox.add_artist(shadow1)
offsetbox.add_artist(text_patch)
ab = AnnotationBbox(offsetbox,(pos[0],pos[1]),xycoords='data',frameon=False)
ax.add_artist(ab)
# plt.annotate(ar_number,xy=(pos[0],pos[1]),color='white',weight=600,stretch='condensed')
# plt.annotate(ar_number,xy=(pos[0],pos[1]),weight=500)
return map_fig
开发者ID:dpshelio,项目名称:smpy,代码行数:23,代码来源:images.py
示例11: draw
def draw(self, renderer, *args, **kwargs):
if not self.get_visible():
return
if not self.get_mappable():
return
# Get parameters
from matplotlib import rcParams # late import
def _get_value(attr, default):
value = getattr(self, attr)
if value is None:
value = rcParams.get('colorbar.' + attr, default)
return value
orientation = _get_value('orientation', 'vertical')
length_fraction = _get_value('length_fraction', 0.2)
width_fraction = _get_value('width_fraction', 0.01)
location = _get_value('location', 'upper right')
if is_string_like(location):
location = self._LOCATIONS[location]
pad = _get_value('pad', 0.2)
border_pad = _get_value('border_pad', 0.1)
sep = _get_value('sep', 5)
frameon = _get_value('frameon', True)
color = _get_value('color', 'k')
box_color = _get_value('box_color', 'w')
box_alpha = _get_value('box_alpha', 1.0)
font_properties = self.font_properties
ticklocation = _get_value('ticklocation', 'auto')
if ticklocation == 'auto':
ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
mappable = self.mappable
cmap = self.mappable.cmap
label = self.label
ticks = self.ticks
ticklabels = self.ticklabels
ax = self.axes
# Calculate
calculator = ColorbarCalculator(mappable, ticks=ticks, ticklabels=ticklabels)
X, Y, C = calculator.calculate_colorbar()
X *= width_fraction
Y *= length_fraction
widths = np.diff(X, axis=1)[:, 0]
heights = np.diff(Y[:, 0])
if orientation == 'horizontal':
X, Y = Y, X
widths, heights = heights, widths
ticks, ticklabels, offset_string = calculator.calculate_ticks()
ticks *= length_fraction
# Create colorbar
colorbarbox = AuxTransformBox(ax.transAxes)
patches = []
for x0, y0, width, height in zip(X[:-1, 0], Y[:-1, 0], widths, heights):
patch = Rectangle((x0, y0), width, height)
patches.append(patch)
edgecolors = 'none' #if self.drawedges else 'none'
#FIXME: drawedge property
#FIXME: Filled property
col = PatchCollection(patches, cmap=cmap, edgecolors=edgecolors)
col.set_array(C[:, 0])
colorbarbox.add_artist(col)
# Create outline
if orientation == 'horizontal':
outline = Rectangle((0, 0), length_fraction, width_fraction,
fill=False, ec=color)
else:
outline = Rectangle((0, 0), width_fraction, length_fraction,
fill=False, ec=color)
colorbarbox.add_artist(outline)
# Create ticks and tick labels
w10th = width_fraction / 10.0
ticklines = []
ticktexts = []
for tick, ticklabel in zip(ticks, ticklabels):
if ticklocation == 'bottom':
x0 = x1 = xtext = tick
y0 = w10th
y1 = -w10th
ytext = -2 * w10th
ha = 'center'
va = 'top'
elif ticklocation == 'top':
x0 = x1 = xtext = tick
y0 = width_fraction - w10th
y1 = width_fraction + w10th
ytext = width_fraction + 2 * w10th
ha = 'center'
va = 'bottom'
elif ticklocation == 'left':
x0 = w10th
#.........这里部分代码省略.........
开发者ID:ppinard,项目名称:matplotlib-colorbar,代码行数:101,代码来源:colorbar.py
示例12: 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)
开发者ID:dreadtoad,项目名称:pywcsgrid2,代码行数:91,代码来源:aux_artists.py
示例13: get_sample_data
# EXAMPLE 1
ax = plt.subplot(211)
from matplotlib._png import read_png
fn = get_sample_data("lena.png", asfileobj=False)
arr = read_png(fn)
text_path = TextPath((0, 0), "!?", size=150)
p = PathClippedImagePatch(text_path, arr, ec="k",
transform=IdentityTransform())
#p.set_clip_on(False)
# make offset box
offsetbox = AuxTransformBox(IdentityTransform())
offsetbox.add_artist(p)
# make anchored offset box
ao = AnchoredOffsetbox(loc=2, child=offsetbox, frameon=True, borderpad=0.2)
ax.add_artist(ao)
# another text
from matplotlib.patches import PathPatch
if usetex:
r = r"\mbox{textpath supports mathtext \& \TeX}"
else:
r = r"textpath supports mathtext & TeX"
text_path = TextPath((0, 0), r,
size=20, usetex=usetex)
开发者ID:AlexSzatmary,项目名称:matplotlib,代码行数:31,代码来源:demo_text_path.py
示例14: __init__
#.........这里部分代码省略.........
head_width : int or float, optional
Width of arrow head, sent to ArrowStyle.
Defaults to 10.
head_length : int or float, optional
Length of arrow head, sent to ArrowStyle.
Defaults to 15.
tail_width : int or float, optional
Width of arrow tail, sent to ArrowStyle.
Defaults to 2.
text_props, arrow_props : dict
Properties of the text and arrows, passed to
:class:`matplotlib.text.TextPath` and
`matplotlib.patches.FancyArrowPatch`
**kwargs
Keyworded arguments to pass to
:class:`matplotlib.offsetbox.AnchoredOffsetbox`.
Attributes
----------
arrow_x, arrow_y : `matplotlib.patches.FancyArrowPatch`
Arrow x and y
text_path_x, text_path_y : `matplotlib.text.TextPath`
Path for arrow labels
p_x, p_y : `matplotlib.patches.PathPatch`
Patch for arrow labels
box : `matplotlib.offsetbox.AuxTransformBox`
Container for the arrows and labels.
Notes
-----
If *prop* is passed as a keyword argument, but *fontproperties* is
not, then *prop* is be assumed to be the intended *fontproperties*.
Using both *prop* and *fontproperties* is not supported.
Examples
--------
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from mpl_toolkits.axes_grid1.anchored_artists import (
... AnchoredDirectionArrows)
>>> fig, ax = plt.subplots()
>>> ax.imshow(np.random.random((10,10)))
>>> arrows = AnchoredDirectionArrows(ax.transAxes, '111', '110')
>>> ax.add_artist(arrows)
>>> fig.show()
Using several of the optional parameters, creating downward pointing
arrow and high contrast text labels.
>>> import matplotlib.font_manager as fm
>>> fontprops = fm.FontProperties(family='monospace')
>>> arrows = AnchoredDirectionArrows(ax.transAxes, 'East', 'South',
... loc='lower left', color='k',
... aspect_ratio=-1, sep_x=0.02,
... sep_y=-0.01,
... text_props={'ec':'w', 'fc':'k'},
... fontproperties=fontprops)
"""
开发者ID:QuLogic,项目名称:matplotlib,代码行数:67,代码来源:anchored_artists.py
示例15: __init__
def __init__(self, transform, size, label, loc,
pad=0.1, borderpad=0.1, sep=2, prop=None,
frameon=True, size_vertical=0, color='black',
label_top=False,
**kwargs):
"""
Draw a horizontal bar with the size in data coordinate of the give axes.
A label will be drawn underneath (center-aligned).
Parameters:
-----------
transform : matplotlib transformation object
size : int or float
horizontal length of the size bar, given in data coordinates
label : str
loc : int
pad : int or float, optional
in fraction of the legend font size (or prop)
borderpad : int or float, optional
in fraction of the legend font size (or prop)
sep : int or float, optional
in points
frameon : bool, optional
if True, will draw a box around the horizontal bar and label
size_vertical : int or float, optional
vertical length of the size bar, given in data coordinates
color : str, optional
color for the size bar and label
label_top : bool, optional
if true, the label will be over the rectangle
Example:
--------
>>>> import matplotlib.pyplot as plt
>>>> import numpy as np
>>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
>>>> fig, ax = plt.subplots()
>>>> ax = imshow(np.random.random((10,10)))
>>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', pad=0.5, loc=4, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white')
>>>> ax.add_artist(bar)
>>>> plt.show()
"""
self.size_bar = AuxTransformBox(transform)
self.size_bar.add_artist(Rectangle((0,0), size, size_vertical, fill=True, facecolor=color, edgecolor=color))
self.txt_label = TextArea(label, minimumdescent=False)
if label_top:
_box_children = [self.txt_label, self.size_bar]
else:
_box_children = [self.size_bar, self.txt_label]
self._box = VPacker(children=_box_children,
align="center",
pad=0, sep=sep)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=self._box,
prop=prop,
frameon=frameon, **kwargs)
开发者ID:BenFrantzDale,项目名称:matplotlib,代码行数:62,代码来源:anchored_artists.py
示例16: draw
def draw(self, renderer, *args, **kwargs):
if not self.get_visible():
return
if not self.get_mappable():
return
# Get parameters
from matplotlib import rcParams # late import
cmap = self.mappable.get_cmap()
array = self.mappable.get_array()
label = self.label
orientation = self.orientation or \
rcParams.get('colorbar.orientation', 'vertical')
nbins = self.nbins or rcParams.get('colorbar.nbins', 50)
length_fraction = self.length_fraction or \
rcParams.get('colorbar.length_fraction', 0.2)
width_fraction = self.width_fraction or \
rcParams.get('colorbar.width_fraction', 0.01)
location = self.location or \
self._LOCATIONS[rcParams.get('colorbar.location', 'upper right')]
pad = self.pad or rcParams.get('colorbar.pad', 0.2)
border_pad = self.border_pad or \
rcParams.get('colorbar.border_pad', 0.1)
sep = self.sep or rcParams.get('colorbar.sep', 5)
frameon = self.frameon or rcParams.get('colorbar.frameon', True)
color = self.color or rcParams.get('colorbar.color', 'k')
box_color = self.box_color or rcParams.get('colorbar.box_color', 'w')
box_alpha = self.box_alpha or rcParams.get('colorbar.box_alpha', 1.0)
font_properties = self.font_properties
ticks = self.ticks
ticklabels = self.ticklabels
ax = self.axes
children = []
# Create colorbar
colorbarbox = AuxTransformBox(ax.transData)
xlim, ylim = ax.get_xlim(), ax.get_ylim()
if orientation == 'horizontal':
length = abs(xlim[1] - xlim[0]) * length_fraction
width = abs(ylim[1] - ylim[0]) * width_fraction
else:
length = abs(ylim[1] - ylim[0]) * length_fraction
width = abs(xlim[1] - xlim[0]) * width_fraction
step_length = length / nbins
patches = []
for x in np.arange(0, length, step_length):
if orientation == 'horizontal':
patch = Rectangle((x, 0), step_length, width)
else:
patch = Rectangle((0, x), width, step_length)
patches.append(patch)
values = np.linspace(np.min(array), np.max(array), nbins)
minvalue, maxvalue = values[0], values[-1]
col = PatchCollection(patches, cmap=cmap,
edgecolors='none')
col.set_array(values)
colorbarbox.add_artist(col)
if orientation == 'horizontal':
patch = Rectangle((0, 0), length, width, fill=False, ec=color)
else:
patch = Rectangle((0, 0), width, length, fill=False, ec=color)
colorbarbox.add_artist(patch)
children.append(colorbarbox)
# Create ticks
tickbox = AuxTransformBox(ax.transData)
if ticks is None:
ticks = [minvalue, maxvalue] # default
if not ticklabels:
ticklabels = ticks[:] # tick label by default
if minvalue not in ticks: # little hack to get right layout position
ticks.append(minvalue)
ticklabels.append('') # no label for this extra tick
if maxvalue not in ticks: # little hack to get right layout position
ticks.append(maxvalue)
ticklabels.append('') # no label for this extra tick
for itick, tick in enumerate(ticks):
if tick > maxvalue or tick < minvalue:
continue # ignore it
# Fraction of colorbar depending of min and max values of colorbar
a = 1 / (maxvalue - minvalue)
b = -a * minvalue
tickfrac = a * tick + b
if orientation == 'horizontal':
#.........这里部分代码省略.........
开发者ID:jnth,项目名称:matplotlib-colorbar,代码行数:101,代码来源:colorbar.py
示例17: __init__
def __init__(self, transform, size, label, loc,
pad=0.1, borderpad=0.1, sep=2,
frameon=True, size_vertical=0, color='black',
label_top=False, fontproperties=None,
**kwargs):
"""
Draw a horizontal bar with the size in data coordinate of the given axes.
A label will be drawn underneath (center-aligned).
Parameters:
-----------
transform : matplotlib transformation object
size : int or float
horizontal length of the size bar, given in data coordinates
label : str
loc : int
pad : int or float, optional
in fraction of the legend font size (or prop)
borderpad : int or float, optional
in fraction of the legend font size (or prop)
sep : int or float, optional
in points
frameon : bool, optional
if True, will draw a box around the horizontal bar and label
size_vertical : int or float, optional
vertical length of the size bar, given in data coordinates
color : str, optional
color for the size bar and label
label_top : bool, optional
if True, the label will be over the rectangle
fontproperties: a matplotlib.font_manager.FontProperties instance, optional
sets the font properties for the label text
Returns:
--------
AnchoredSizeBar object
Example:
--------
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
>>> fig, ax = plt.subplots()
>>> ax.imshow(np.random.random((10,10)))
>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4)
>>> ax.add_artist(bar)
>>> fig.show()
Using all the optional parameters
>>> import matplotlib.font_manager as fm
>>> fontprops = fm.FontProperties(size=14, family='monospace')
>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white', fontproperties=fontprops) # noqa
"""
self.size_bar = AuxTransformBox(transform)
self.size_bar.add_artist(Rectangle((0, 0), size, size_vertical,
fill=True, facecolor=color,
edgecolor=color))
# if fontproperties is None, but `prop` is not, assume that
# prop should be used to set the font properties. This is
# questionable behavior
if fontproperties is None and 'prop' in kwargs:
fontproperties = kwargs.pop('prop')
if fontproperties is None:
textprops = {'color': color}
else:
textprops = {'color': color, 'fontproperties': fontproperties}
self.txt_label = TextArea(
label,
minimumdescent=False,
textprops=textprops)
if label_top:
_box_children = [self.txt_label, self.size_bar]
else:
_box_children = [self.size_bar, self.txt_label]
self._box = VPacker(children=_box_children,
align="center",
pad=0, sep=sep)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=self._box,
prop=fontproperties,
frameon=frameon, **kwargs)
开发者ID:AbhiK24,项目名称:matpl |
请发表评论