# plot order

Ok, I've spent a while searching through the mailing list archives and I can't find an answer for this relatively simple problem. I've plotted a series of contourf and contour plots on the same axes.

First I plot a contourf.
Next a contour on top of it.
Then I want a contourf plotted on top of both the previous contourf and contour plots.
And finally, a contour on top of the second contourf.

However, when I do this the result is the two contour plots are drawn on top of the contourf plots no matter what. How do I hide the contours under a contourf?

Jordan

zorder.

It won't really matter what order you plot, as long as you set the zorder of the objects to the order you want. However, there is no set_zorder for the whole contour, rather just for each element in the collection. Observe:

pc = contour(random.rand(10,10))
pcf = contourf(random.rand(10,10), cmap=cm.gray)
# now the contours are on top

for l in pc.collections:
l.set_zorder(-100)

draw()
# now the contours are on the bottom

I guess the advantage is that you could pick and choose which contours to expose:

for l in pcf.collections[::2]:
l.set_zorder(-1000)

draw()
# woven contours and contourfs...

-Rob

···

On Jan 24, 2008, at 8:11 AM, Jordan Dawe wrote:

However, when I do this the result is the two contour plots are drawn on
top of the contourf plots no matter what. How do I hide the contours
under a contourf?

----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331

pc = contour(random.rand(10,10))
pcf = contourf(random.rand(10,10), cmap=cm.gray)
# now the contours are on top

for l in pc.collections:
l.set_zorder(-100)

draw()
# now the contours are on the bottom

Well, that's certainly kludgey, but it worked great. Thanks.

Jordan

Jordan Dawe wrote:

pc = contour(random.rand(10,10))
pcf = contourf(random.rand(10,10), cmap=cm.gray)
# now the contours are on top

for l in pc.collections:
l.set_zorder(-100)

draw()
# now the contours are on the bottom

Well, that's certainly kludgey, but it worked great. Thanks.

Maybe contour, contourf, and any similar plotting commands that do not support zorder as a kwarg should do so? I am not sure if this is needed often enough to warrant the extra code and documentation.

Eric

Eric Firing wrote:

Maybe contour, contourf, and any similar plotting commands that do not support zorder as a kwarg should do so? I am not sure if this is needed often enough to warrant the extra code and documentation.

I can't speak for other people, but I use this kind of functionality in nearly every plot I do. Usually I contourf a field in 4-level greyscale, then contour over that to make 8 contour levels, then contourf over _that_ to mask land points (I run models so I have 'land' arrays I can use for this). Sometimes I them put polygons (sometimes transparent) over that to highlight regions. Usually how I've been doing this is by going in to illustrator and manually altering the stacking of the plot elements. Ideally how I wish it worked was that the default zorder was set by a counter, so the oldest plots on an axis would be buried under the newer ones.

Jordan