Discussion:
[Matplotlib-users] Inset plot with a previously draw plot
Alejandro Weinstein
2015-10-29 16:07:16 UTC
Permalink
Hi,

I have a previously draw plot that I want to place as an inset in
another figure. I've tried with passing the previously drawn axes as
the `axes` parameter to the `add_axes` method of the figure, and also
tried using the `set_axes` method of the new axes, without success: I
get the new inset axes, but without the previously drawn plot, in both
cases.

The following code shows both approaches:

# Passing the inset axes as a parameter to add_axes
fig_in, ax_in = plt.subplots()
ax_in.plot([1,2,3])
fig, ax = plt.subplots()
ax.plot([1,2,1])
fig.add_axes([0.72, 0.72, 0.16, 0.16], axes=ax_in)

# Using set_axes
fig_in, ax_in = plt.subplots()
ax_in.plot([1,2,3])
fig, ax = plt.subplots()
ax.plot([1,2,1])
ax_new = fig.add_axes([0.72, 0.72, 0.16, 0.16])
ax_new.set_axes(ax_in)

Any help with this will be appreciated.

Regards,
Alejandro

------------------------------------------------------------------------------
Benjamin Root
2015-10-29 16:19:12 UTC
Permalink
An axes can only belong to one figure at a time. And I also don't think I
have ever seen anyone try and transfer an axes from one figure to another.

You *might* have luck with inset locators from axes_grid:
http://matplotlib.org/examples/axes_grid/inset_locator_demo.html

Cheers!
Ben Root

On Thu, Oct 29, 2015 at 12:07 PM, Alejandro Weinstein <
Post by Alejandro Weinstein
Hi,
I have a previously draw plot that I want to place as an inset in
another figure. I've tried with passing the previously drawn axes as
the `axes` parameter to the `add_axes` method of the figure, and also
tried using the `set_axes` method of the new axes, without success: I
get the new inset axes, but without the previously drawn plot, in both
cases.
# Passing the inset axes as a parameter to add_axes
fig_in, ax_in = plt.subplots()
ax_in.plot([1,2,3])
fig, ax = plt.subplots()
ax.plot([1,2,1])
fig.add_axes([0.72, 0.72, 0.16, 0.16], axes=ax_in)
# Using set_axes
fig_in, ax_in = plt.subplots()
ax_in.plot([1,2,3])
fig, ax = plt.subplots()
ax.plot([1,2,1])
ax_new = fig.add_axes([0.72, 0.72, 0.16, 0.16])
ax_new.set_axes(ax_in)
Any help with this will be appreciated.
Regards,
Alejandro
------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Loading...