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)
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)