Bug in mplot3d contourf

I’ve found a bug in mplot3d’s rendering of filled contours. Attached is a simple test script to reproduce the error and an example of the output: the 2D plot on the left shows the desired result, the 3D plot on the right shows the holes in the contour are not rendered correctly.

Digging around in axes3d.py and art3d.py, I think the problem is that mplot3d ignores the ‘codes’ that are produced by the 2D contourf routine. I am probably not using the correct terminology, but I understand that these codes allow a polygon to be composed of multiple line loops, some of which may be holes within other line loops. By ignoring the codes, the 3D routine renders a single polygon by concatenating all the points together regardless of whether they correspond to a hole or not.

In revision 8806 of lib/mpl_toolkits/mplot3d/art3d.py, lines 136-7:

for (((x, y), code), z) in zip(pathsegs, zs):
seg.append((x, y, z))

The codes are extracted from the pathsegs (which come from the 2D contourf routine), but then ignored.

I’ve taken a look at trying to fix this, but it was not obvious to me how to propagate the ‘codes’ rendering functionality from the 2D to 3D source code. Perhaps someone more familiar with mplot3d could look at it.

Thanks,
Ian

bug3d.py (333 Bytes)

bug3d.png

Confirmed. Ian, would you mind filing a bug report on this at mpl’s tracker?

http://sourceforge.net/tracker/?atid=560720&group_id=80706&func=browse

Thank you very much for your insightful analysis as well. It will be helpful in finding a fix for this.

Ben Root

···

On Mon, Nov 22, 2010 at 3:30 AM, Ian Thomas <ianthomas23@…746…49…> wrote:

I’ve found a bug in mplot3d’s rendering of filled contours. Attached is a simple test script to reproduce the error and an example of the output: the 2D plot on the left shows the desired result, the 3D plot on the right shows the holes in the contour are not rendered correctly.

Digging around in axes3d.py and art3d.py, I think the problem is that mplot3d ignores the ‘codes’ that are produced by the 2D contourf routine. I am probably not using the correct terminology, but I understand that these codes allow a polygon to be composed of multiple line loops, some of which may be holes within other line loops. By ignoring the codes, the 3D routine renders a single polygon by concatenating all the points together regardless of whether they correspond to a hole or not.

In revision 8806 of lib/mpl_toolkits/mplot3d/art3d.py, lines 136-7:

for (((x, y), code), z) in zip(pathsegs, zs):
seg.append((x, y, z))

The codes are extracted from the pathsegs (which come from the 2D contourf routine), but then ignored.

I’ve taken a look at trying to fix this, but it was not obvious to me how to propagate the ‘codes’ rendering functionality from the 2D to 3D source code. Perhaps someone more familiar with mplot3d could look at it.

Thanks,
Ian

I’ve added a bug report:
http://sourceforge.net/tracker/?func=detail&aid=3116341&group_id=80706&atid=560720

Thanks Ben,
Ian

···

On 22 November 2010 19:08, Benjamin Root <ben.root@…553…> wrote:

Confirmed. Ian, would you mind filing a bug report on this at mpl’s tracker?