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