Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How do I view "hidden" contour lines on a surface?

Asked by Joe on 27 Feb 2014
Latest activity Commented on by Joe on 27 Feb 2014

The following Matlab code produces a 3d surface plot with a superimposed contour line. The resulting contour line has several missing segments. If I manually rotate the surface, I can see the missing segments behind the surface. Is there some way to make the entire contour line visible?

x=linspace(0,3,10); y=linspace(0,2,10);

z=[ 2.08, 2.04, 1.91, 1.64, 1.21, 0.74, 0.66, 0.55, 0.33, 0.00; 2.01, 1.87, 1.66, 1.39, 1.03, 0.73, 0.65, 0.47, 0.17, 0.00; 1.79, 1.68, 1.29, 1.11, 0.85, 0.73, 0.56, 0.20, 0.00, 0.00; 1.75, 1.62, 1.20, 0.99, 0.66, 0.59, 0.47, 0.00, 0.00, 0.00; 1.51, 1.35, 1.08, 0.67, 0.53, 0.57, 0.22, 0.00, 0.00, 0.00; 1.06, 0.81, 0.69, 0.38, 0.46, 0.40, 0.00, 0.00, 0.00, 0.00; 0.45, 0.38, 0.21, 0.12, 0.31, 0.04, 0.00, 0.00, 0.00, 0.00; 0.06, 0.04, 0.00, 0.01, 0.09, 0.00, 0.00, 0.00, 0.00, 0.00; 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00; 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00];

figure; surf(x, y, z); hold on

view(120,40); colormap(winter)

[C,h]=contour3(x, y, z, [1.0 1.0], 'r');

0 Comments

Joe

Tags

Products

No products are associated with this question.

1 Answer

Answer by John D'Errico on 27 Feb 2014

I'd suggest turning the surface mildly transparent. In the call to surf, try this instead:

surf(x, y, z,'facealpha',.5)

The rest stays the same.

2 Comments

Walter Roberson on 27 Feb 2014

One effect of using transparency would be to force OpenGL renderer. But if that was not what was being used then just the switch of renderer might be the trick rather than the transparency itself. Try

set(gcf, 'Renderer', 'opengl')
Joe on 27 Feb 2014

John and Walter, Thanks for your quick responses! I first tried changing the transparency as John suggested. That works, now I can I see the entire contour line. However, the surface color scale washes out, so it's hard to distinguish dark blue from light blue, and the red contour line becomes grey when it passes behind the surface. I tried various alpha values, but I haven't found one where both the surface and the contour line look good.

Next, I tried varying the renderer, as Walter suggested (with alpha=1). The painters renderer actually shows more of the contour line than OpenGL, but parts of it still disappear behind the surface.

Any other ideas?

- Joe

John D'Errico

Contact us