[Matplotlib-users] imshow zorder

Any idea if the "wart" can be removed? I tried to use zorder with the
SVN matplotlib (in conjuction with alpha-transparency, it can give a
great way to represent missing data in waterfall diagram)
but without success, image is still always in the back....
I did not use imshow, but NonUniformImage, but I guess the problem is
the same for all AxisImage instances...

BTW, I also submitted a patch to NonUniformImage to allows for bilinear
interpolation on rectangular non-uniform grids. I think the original
code was yours, so maybe you have something to say about the patch :wink:

Best regards,



On Tue, 2007-11-20 at 11:15 -1000, Eric Firing wrote:

Jeff Whitaker wrote:
> If I draw two images with imshow, then set_zorder for one of them to be
> higher than the other, should that one be the one that displays?


It is a wart. Images are handled separately from other artists, and
always drawn first, either as a composite or in the order in which they
were added to the list. Here is the relevant code in the Axes.draw()

         if len(self.images)<=1 or renderer.option_image_nocomposite():
             for im in self.images:
             # make a composite image blending alpha
             # list of (mimage.Image, ox, oy)

             mag = renderer.get_image_magnification()
             ims = [(im.make_image(mag),0,0)
                    for im in self.images if im.get_visible()]

             im = mimage.from_images(self.bbox.height()*mag,
             im.is_grayscale = False
             l, b, w, h = self.bbox.get_bounds()
             # composite images need special args so they will not
             # respect z-order for now
             renderer.draw_image(l, b, im, self.bbox)

Maybe the set_zorder method for images should raise a warning, since it
  can't do what one might reasonably expect.

Mike may be able to comment on the prospects for removing this wart at
some point in the transforms branch; he is looking at related questions
right now.


> for example, with
> from pylab import *
> delta = 0.025
> x = y = arange(-3.0, 3.0, delta)
> X, Y = meshgrid(x, y)
> Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
> Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
> Z = Z2-Z1 # difference of Gaussians
> im2 = imshow(Z2, interpolation='bilinear', cmap=cm.gray,
> origin='lower', extent=[-3,3,-3,3])
> im2.set_zorder(2)
> im1 = imshow(Z1, interpolation='bilinear', cmap=cm.gray,
> origin='lower', extent=[-3,3,-3,3])
> im1.set_zorder(1)
> show()
> I expected Z2 to be plotted, but I actually see Z1. In fact, I always
> see the last one that was plotted, regardless of what I set the zorder to.
> I'm using the latest SVN, with GTKAgg.
> -Jeff