本文整理汇总了Python中matplotlib.offsetbox.AnchoredOffsetbox类的典型用法代码示例。如果您正苦于以下问题:Python AnchoredOffsetbox类的具体用法?Python AnchoredOffsetbox怎么用?Python AnchoredOffsetbox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnchoredOffsetbox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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)
示例2: __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)
示例3: __init__
def __init__(self, transform, loc, pad=0.4, borderpad=0.5, prop=None, frameon=True, **kwargs):
self.drawing_area = AuxTransformBox(transform)
AnchoredOffsetbox.__init__(
self, loc, pad=pad, borderpad=borderpad, child=self.drawing_area, prop=prop, frameon=frameon, **kwargs
)
示例4: __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)
示例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)
示例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,
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
)
示例7: anchor_legend
def anchor_legend(ax, box, row, col):
anchored = AnchoredOffsetbox(loc=2,
child=box,
pad=0.,
frameon=False,
bbox_to_anchor=(1 + 0.25*col, 1 - 0.054*row),
bbox_transform=ax.transAxes,
)
# Workaround for a bug in matplotlib up to 1.3.1
# https://github.com/matplotlib/matplotlib/issues/2530
anchored.set_clip_on(False)
ax.add_artist(anchored)
示例8: __init__
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)
示例9: __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)
示例10: __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)
示例11: draw_legend
def draw_legend(ax, legend, legend_type, legend_title, ith_legend):
children = []
children.append(make_title(legend_title))
viz_handler = legend_viz[legend_type]
legend_items = sorted(legend.items(), key=operator.itemgetter(1))
children += [viz_handler(str(lab), col) for col, lab in legend_items]
box = VPacker(children=children, align="left", pad=0, sep=5)
# TODO: The vertical spacing between the legends isn't consistent. Should be
# padded consistently
anchored_box = AnchoredOffsetbox(loc=6,
child=box, pad=0.,
frameon=False,
#bbox_to_anchor=(0., 1.02),
# Spacing goes here
bbox_to_anchor=(1, 0.8 - 0.35 * ith_legend),
bbox_transform=ax.transAxes,
borderpad=1.,
)
# Workaround for a bug in matplotlib up to 1.3.1
# https://github.com/matplotlib/matplotlib/issues/2530
anchored_box.set_clip_on(False)
return anchored_box
示例12: __init__
def __init__(self, transform, loc,
pad=0.4, borderpad=0.5, prop=None, frameon=True, **kwargs):
"""
An anchored container with transformed coordinates.
Artists added to the *drawing_area* are scaled according to the
coordinates of the transformation used. The dimensions of this artist
will scale to contain the artists added.
Parameters
----------
transform : `matplotlib.transforms.Transform`
The transformation object for the coordinate system in use, i.e.,
:attr:`matplotlib.axes.Axes.transData`.
loc : int
Location of this artist. Valid location codes are::
'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
pad : int or float, optional
Padding around the child objects, in fraction of the font
size. Defaults to 0.4.
borderpad : int or float, optional
Border padding, in fraction of the font size.
Defaults to 0.5.
prop : `matplotlib.font_manager.FontProperties`, optional
Font property used as a reference for paddings.
frameon : bool, optional
If True, draw a box around this artists. Defaults to True.
**kwargs
Keyworded arguments to pass to
:class:`matplotlib.offsetbox.AnchoredOffsetbox`.
Attributes
----------
drawing_area : `matplotlib.offsetbox.AuxTransformBox`
A container for artists to display.
Examples
--------
To display an ellipse in the upper left, with a width of 0.1 and
height of 0.4 in data coordinates:
>>> box = AnchoredAuxTransformBox(ax.transData, loc='upper left')
>>> el = Ellipse((0,0), width=0.1, height=0.4, angle=30)
>>> box.drawing_area.add_artist(el)
>>> ax.add_artist(box)
"""
self.drawing_area = AuxTransformBox(transform)
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=self.drawing_area,
prop=prop,
frameon=frameon,
**kwargs)
示例13: draw
#.........这里部分代码省略.........
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
x1 = -w10th
xtext = -2 * w10th
y0 = y1 = ytext = tick
ha = 'right'
va = 'center'
elif ticklocation == 'right':
x0 = width_fraction - w10th
x1 = width_fraction + w10th
xtext = width_fraction + 2 * w10th
y0 = y1 = ytext = tick
ha = 'left'
va = 'center'
ticklines.append([(x0, y0), (x1, y1)])
ticklabel = offset_string + ticklabel
ticktext = Text(xtext, ytext, ticklabel,
color=color,
fontproperties=font_properties,
horizontalalignment=ha,
verticalalignment=va)
ticktexts.append(ticktext)
col = LineCollection(ticklines, color=color)
colorbarbox.add_artist(col)
for ticktext in ticktexts:
colorbarbox.add_artist(ticktext)
# Create label
if label:
labelbox = AuxTransformBox(ax.transAxes)
va = 'baseline' if orientation == 'horizontal' else 'center'
text = Text(0, 0, label,
fontproperties=font_properties,
verticalalignment=va,
rotation=orientation,
color=color)
labelbox.add_artist(text)
else:
labelbox = None
# Create final offset box
if ticklocation == 'bottom':
children = [colorbarbox, labelbox] if labelbox else [colorbarbox]
child = VPacker(children=children, align='center', pad=0, sep=sep)
elif ticklocation == 'top':
children = [labelbox, colorbarbox] if labelbox else [colorbarbox]
child = VPacker(children=children, align='center', pad=0, sep=sep)
elif ticklocation == 'left':
children = [labelbox, colorbarbox] if labelbox else [colorbarbox]
child = HPacker(children=children, align='center', pad=0, sep=sep)
elif ticklocation == 'right':
children = [colorbarbox, labelbox] if labelbox else [colorbarbox]
child = HPacker(children=children, align='center', pad=0, sep=sep)
#
box = AnchoredOffsetbox(loc=location,
pad=pad,
borderpad=border_pad,
child=child,
frameon=frameon)
box.axes = ax
box.set_figure(self.get_figure())
box.patch.set_color(box_color)
box.patch.set_alpha(box_alpha)
box.draw(renderer)
示例14: draw
#.........这里部分代码省略.........
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':
tickx = tickfrac * length
ticky = 0
ha = 'center'
va = 'top'
else:
tickx = width
ticky = tickfrac * length
ha = 'left'
va = 'center'
ticktext = Text(tickx, ticky, ticklabels[itick],
color=color,
fontproperties=font_properties,
horizontalalignment=ha,
verticalalignment=va)
tickbox.add_artist(ticktext)
children.append(tickbox)
# Create label
if label:
labelbox = AuxTransformBox(ax.transData)
va = 'baseline' if orientation == 'horizontal' else 'center'
text = Text(0, 0, label,
fontproperties=font_properties,
verticalalignment=va,
rotation=orientation)
labelbox.add_artist(text)
children.insert(0, labelbox)
# Create final offset box
Packer = VPacker if orientation == 'horizontal' else HPacker
child = Packer(children=children, align="center", pad=0, sep=sep)
box = AnchoredOffsetbox(loc=location,
pad=pad,
borderpad=border_pad,
child=child,
frameon=frameon)
box.axes = ax
box.set_figure(self.get_figure())
box.patch.set_color(box_color)
box.patch.set_alpha(box_alpha)
box.draw(renderer)
示例15: _draw_legend
def _draw_legend(self):
"""
Draw legend onto the figure
"""
legend_box = self.guides.build(self)
if not legend_box:
return
figure = self.figure
left = figure.subplotpars.left
right = figure.subplotpars.right
top = figure.subplotpars.top
bottom = figure.subplotpars.bottom
W, H = figure.get_size_inches()
position = self.guides.position
get_property = self.theme.themeables.property
# defaults
spacing = 0.1
strip_margin_x = 0
strip_margin_y = 0
with suppress(KeyError):
spacing = get_property('legend_box_spacing')
with suppress(KeyError):
strip_margin_x = get_property('strip_margin_x')
with suppress(KeyError):
strip_margin_y = get_property('strip_margin_y')
right_strip_width = self.facet.strip_size('right')
top_strip_height = self.facet.strip_size('top')
# Other than when the legend is on the right the rest of
# the computed x, y locations are not gauranteed not to
# overlap with the axes or the labels. The user must then
# use the legend_margin theme parameter to adjust the
# location. This should get fixed when MPL has a better
# layout manager.
if position == 'right':
loc = 6
pad = right_strip_width*(1+strip_margin_x) + spacing
x = right + pad/W
y = 0.5
elif position == 'left':
loc = 7
x = left - spacing/W
y = 0.5
elif position == 'top':
loc = 8
x = 0.5
pad = top_strip_height*(1+strip_margin_y) + spacing
y = top + pad/H
elif position == 'bottom':
loc = 9
x = 0.5
y = bottom - spacing/H
else:
loc = 10
x, y = position
anchored_box = AnchoredOffsetbox(
loc=loc,
child=legend_box,
pad=0.,
frameon=False,
bbox_to_anchor=(x, y),
bbox_transform=figure.transFigure,
borderpad=0.)
anchored_box.set_zorder(90.1)
self.figure._themeable['legend_background'] = anchored_box
ax = self.axs[0]
ax.add_artist(anchored_box)