# imshow zorder

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?

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

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

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?

Jeff,

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() method:

if len(self.images)<=1 or renderer.option_image_nocomposite():
for im in self.images:
im.draw(renderer)
else:
# 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,
self.bbox.width()*mag,
ims)
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.

Eric

···

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