def add_unique_figure_legend(fig: Figure, axes: Axes) -> None: """Add a legend with unique elements sorted by label to a figure. The handles and labels are extracted from the ``axes`` Parameters ---------- fig : Figure Figure to add the legend to. axes : Axes Axes plotted on the figure. See Also -------- plot_fit_overview """ handles = [] labels = [] for ax in axes.flatten(): ax_handles, ax_labels = ax.get_legend_handles_labels() handles += ax_handles labels += ax_labels unique = [(h, l) for i, (h, l) in enumerate(zip(handles, labels)) if l not in labels[:i]] unique.sort(key=lambda entry: entry[1]) fig.legend(*zip(*unique))
def plot_sequence(I: np.ndarray, ax: plt.Axes, funcs: list, **kwargs): if len(funcs) != len(ax) - 1: raise ValueError( f'Received {len(funcs)} functions; expected {len(ax)}') visualizations = [lambda X: X] + funcs axf = ax.flatten() for i, vis in enumerate(visualizations): axf[i].imshow(vis(I), **kwargs)