Skip to content

Instantly share code, notes, and snippets.

@salotz
salotz / move_axes.py
Created March 1, 2019 20:22
Move a matplotlib Axes from one figure to another.
import matplotlib.pyplot as plt
def move_axes(ax, fig, subplot_spec=111):
"""Move an Axes object from a figure to a new pyplot managed Figure in
the specified subplot."""
# get a reference to the old figure context so we can release it
old_fig = ax.figure
# remove the Axes from it's original Figure context