Re using a subplot on two different figures

I apologize if this has been covered, but I couldn't find it by searching.

I'm wondering how one might reuse a single subplot on two different figures.

Here's what I'm trying to do:

import matplotlib.pyplot as plt

fig1 = plt.figure()
fig2 = plt.figure()
ax1 = fig1.add_subplot(311)

#plot lots of stuff on ax1

# I thought maybe I could do something like this, but, of course, that
doesn't work.
ax2 = fig2.add_subplot(311)
ax2 = ax1

Basically, I would like to put ax1 on both fig1 and fig2 without having to
repeat all of the code for plots on ax1.

Thanks for the help!!!
-Doug

···

--
View this message in context: http://old.nabble.com/Reusing-a-subplot-on-two-different-figures-tp27131100p27131100.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Doug,

I'm sure there's a slick, one-line way to do this. I don't know it either. As a quick work around, you could do this:
fig1 = plt.figure()
fig2 = plt.figure()
ax1 = fig1.add_subplot(311)
ax2 = fig2.add_subplot(311)
for ax in [ax1, ax2]:
  # do lots of stuff to ax

At least, that's how I would do it with my very basic MPL knowledge. Hope this wasn't obvious to you and something you were trying to avoid.

HTH,
-Paul H.

···

-----Original Message-----
From: dugolo [mailto:madory@…287…]
Sent: Tuesday, January 12, 2010 9:21 AM
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] Re using a subplot on two different figures

I apologize if this has been covered, but I couldn't find it by
searching.

I'm wondering how one might reuse a single subplot on two different
figures.

Here's what I'm trying to do:

import matplotlib.pyplot as plt

fig1 = plt.figure()
fig2 = plt.figure()
ax1 = fig1.add_subplot(311)

#plot lots of stuff on ax1

# I thought maybe I could do something like this, but, of course, that
doesn't work.
ax2 = fig2.add_subplot(311)
ax2 = ax1

Basically, I would like to put ax1 on both fig1 and fig2 without having
to
repeat all of the code for plots on ax1.

The Axes instances in matplotlib can only have one parent figure,
i.e., the axes cannot be shared among different figures.

But this does not necessarily imply that you have to repeat the
drawing code. Just define a function that takes an axes, or use some
control structure as suggested above.

Regards,

-JJ

···

On Tue, Jan 12, 2010 at 12:21 PM, dugolo <madory@...287...> wrote:

Basically, I would like to put ax1 on both fig1 and fig2 without having to
repeat all of the code for plots on ax1.