本文整理汇总了Python中matplotlib.offsetbox.AnchoredOffsetbox.set_zorder方法的典型用法代码示例。如果您正苦于以下问题:Python AnchoredOffsetbox.set_zorder方法的具体用法?Python AnchoredOffsetbox.set_zorder怎么用?Python AnchoredOffsetbox.set_zorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.offsetbox.AnchoredOffsetbox
的用法示例。
在下文中一共展示了AnchoredOffsetbox.set_zorder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_legend
# 需要导入模块: from matplotlib.offsetbox import AnchoredOffsetbox [as 别名]
# 或者: from matplotlib.offsetbox.AnchoredOffsetbox import set_zorder [as 别名]
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)