def relocate_legend(fig: Figure, loc: str) -> Figure: """Relocate legend(s) from center to `loc`.""" remains = [] targets = [] for layout in fig.center: if isinstance(layout, Legend): targets.append(layout) else: remains.append(layout) fig.center = remains for layout in targets: fig.add_layout(layout, loc) return fig