MATLAB: 2D contour in 3D

3d visualizationcontourcontourfplotting

I have a visualization question. I am plotting a slice of data as a 2-dimensional contour using contourf(). What I would like to do is rotate this to show where it sits in 3D, and be able to use the 3D-rotation cursor. The problem is, contourf() really thinks this is just X and Y, and the cursor doesn't want to flip things on it's side. Is there a way to take the contour and plot it in a larger 3D context?

Best Answer

contour() and contourf() work oddly. They call an internal routine that creates patches in 3D at the height of the contour planes, and then they run through and set the Z values to 0 deliberately.
An undocumented trick to this process is that for each patch, the Userdata field of the patch is set to a value which is the Z coordinate. This allows you to post-process, run through the patches, fetch their Userdata, and set the Z values back.