Using imshow() and plot() in the same figure

I have a figure with a number of plots that analyze a source image. I wish to show the plots along side the image. Unfortunately whichever method I call last clobbers (leaves blank axes) for the previously called method.

To illustrate:

fig, axs = pylab.subplots(10, 4, sharex=True, sharey=True)

for i in range(10):

axs[i,0].plot(some_data)
axs[i,1].plot(some_data)
axs[i,2].plot(some_data)

axs[i,3].imshow(some_image)

···

#=====

The above shows only the images in the fourth column. If, however, I call imshow() first, followed by the call to plot(), then only the plot axes appear and the images disappear.

Is there a way to both plot and display images in the same figure?

-Adam

I have a figure with a number of plots that analyze a source image. I
wish to show the plots along side the image. Unfortunately whichever
method I call last clobbers (leaves blank axes) for the previously
called method.

To illustrate:

fig, axs = pylab.subplots(10, 4, sharex=True, sharey=True)

for i in range(10):

   axs[i,0].plot(some_data)
   axs[i,1].plot(some_data)
   axs[i,2].plot(some_data)

axs[i,3].imshow(some_image)

#=====

The above shows only the images in the fourth column. If, however, I
call imshow() first, followed by the call to plot(), then only the plot
axes appear and the images disappear.

Is there a way to both plot and display images in the same figure?

I suspect the problem here is your sharex and sharey kwargs. Try leaving them out.

Eric

···

On 09/04/2011 11:12 AM, Adam Davis wrote:

-Adam

Eric,

Thank you for the reply.

Yes, eliminating sharex and sharey does solve that problem. But then my plot axes (which are scatter plots of each orthogonal view of a vector space) are not correspondingly scaled.

Is there a way to:

  • force scaling across specified axes without using sharex/y (and without disrupting imshow)?

  • have subplots within subplots so that I can have the plot() calls in one set of axes within a subplot (using sharex/y) and the imshow() calls in another subplot?

-Adam

···

On Sun, Sep 4, 2011 at 10:34 PM, Eric Firing <efiring@…202…> wrote:

On 09/04/2011 11:12 AM, Adam Davis wrote:

I have a figure with a number of plots that analyze a source image. I

wish to show the plots along side the image. Unfortunately whichever

method I call last clobbers (leaves blank axes) for the previously

called method.

To illustrate:

fig, axs = pylab.subplots(10, 4, sharex=True, sharey=True)

for i in range(10):

axs[i,0].plot(some_data)

axs[i,1].plot(some_data)

axs[i,2].plot(some_data)

axs[i,3].imshow(some_image)

#=====

The above shows only the images in the fourth column. If, however, I

call imshow() first, followed by the call to plot(), then only the plot

axes appear and the images disappear.

Is there a way to both plot and display images in the same figure?

I suspect the problem here is your sharex and sharey kwargs. Try

leaving them out.

Eric

-Adam


Special Offer – Download ArcSight Logger for FREE!

Finally, a world-class log management solution at an even better

price-free! And you’ll get a free “Love Thy Logs” t-shirt when you

download Logger. Secure your free ArcSight Logger TODAY!

http://p.sf.net/sfu/arcsisghtdev2dev


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Eric,

Thank you for the reply.

Yes, eliminating sharex and sharey does solve that problem. But then my
plot axes (which are scatter plots of each orthogonal view of a vector
space) are not correspondingly scaled.

Is there a way to:

- force scaling across specified axes without using sharex/y (and
without disrupting imshow)?

You can manually get and set the axes limits with ax.get_ylim, ax.set_ylim, etc.

- have subplots within subplots so that I can have the plot() calls in
one set of axes within a subplot (using sharex/y) and the imshow() calls
in another subplot?

You just need to create the subplots one-by-one instead of using the subplots convenience function:

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2, sharex=ax1, sharey=ax1)
ax3 = fig.add_subplot(2,2,3, sharex=ax1, sharey=ax1)
ax4 = fig.add_subplot(2,2,4)

Now the first three axes are locked together, and the 4th is independent.

Eric

···

On 09/04/2011 12:08 PM, Adam Davis wrote:

-Adam

On Sun, Sep 4, 2011 at 10:34 PM, Eric Firing <efiring@...202... > <mailto:efiring@…202…>> wrote:

    On 09/04/2011 11:12 AM, Adam Davis wrote:
     > I have a figure with a number of plots that analyze a source image. I
     > wish to show the plots along side the image. Unfortunately whichever
     > method I call last clobbers (leaves blank axes) for the previously
     > called method.
     >
     > To illustrate:
     >
     > fig, axs = pylab.subplots(10, 4, sharex=True, sharey=True)
     >
     > for i in range(10):
     >
     > axs[i,0].plot(some_data)
     > axs[i,1].plot(some_data)
     > axs[i,2].plot(some_data)
     >
     > axs[i,3].imshow(some_image)
     >
     > #=====
     >
     > The above shows only the images in the fourth column. If, however, I
     > call imshow() first, followed by the call to plot(), then only
    the plot
     > axes appear and the images disappear.
     >
     > Is there a way to both plot and display images in the same figure?

    I suspect the problem here is your sharex and sharey kwargs. Try
    leaving them out.

    Eric

     >
     > -Adam

    ------------------------------------------------------------------------------
    Special Offer -- Download ArcSight Logger for FREE!
    Finally, a world-class log management solution at an even better
    price-free! And you'll get a free "Love Thy Logs" t-shirt when you
    download Logger. Secure your free ArcSight Logger TODAY!
    http://p.sf.net/sfu/arcsisghtdev2dev
    _______________________________________________
    Matplotlib-users mailing list
    Matplotlib-users@lists.sourceforge.net
    <mailto:Matplotlib-users@lists.sourceforge.net>
    matplotlib-users List Signup and Options