On Fri, Mar 30, 2012 at 12:25 PM, eoj <josephmeiring@gmail.com> wrote:

Basically the problem is like this. I have a relatively expensive (time wise)
figure to create, specifically a map with lots of detail in it. On top of
that, I'm  making an inset set of axes to highlight some regions. I'm having
to recreate the base of the map, which is static, every time I want to make
an inset for a different region which is taking forever. What I want to do
is something like this:

fig = figure()

#do stuff that makes the expensive figure

for region in regions:
   fig2 = copy.copy(fig)
   ax2 = fig.add_axes([0.1, 0.15, 0.25, 0.25])

The problem is that the clf() clear figure function seems to clear the base
of the map off, even if I try to make a copy of it inside a loop that is
generating the insets. Also, close() seems to close fig and not fig2. Does
this rambling make any sense, and if so, any suggestions?

If all your additions are confined to the inset axes, you can use `fig.delaxes` to remove the axes from the figure (see example below). If you want to save and restore, as you describe above, you should (in principal) be able to do so with `canvas.copy_from_bbox` and `canvas.restore_region`, but I couldn't get it to work (see bottom of the animation cookbook).


# ~~~ example
import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.imshow(np.random.uniform(size=(10, 10)))

ax_inset = fig.add_axes([0.3, 0.3, 0.2, 0.2])
ax_inset.plot([0, 1])

ax_inset = fig.add_axes([0.5, 0.5, 0.2, 0.2])
ax_inset.plot([1, 0])
# ~~~