Reputation: 893
I'd like to fill a 3D contour plot (contour3(X,Y,Z)
) like the 2D contour fill plot (contourf(X,Y,Z)
). But I can't figure out how this can be achieved. The combination of contour3 and surf is not very satisfying, since there are tiles.
[X,Y,Z] = peaks(32);
figure
contourf(X,Y,Z,15);
figure
contour3(X,Y,Z,15,'k');
hold on;
surf(X,Y,Z, 'Edgecolor', 'none');
contour3(X,Y,Z,15,'k'); hold on; surf(X,Y,Z, 'Edgecolor', 'none');
Upvotes: 3
Views: 4784
Reputation: 111
I had the same problem. You are probably rendering with OpenGL. In order to avoid color jumping more than one adjacent value between contour lines, you need to modify the renderer to Painters:
set (gcf,'Renderer','painters')
Hope that helps!
Upvotes: 0
Reputation: 11812
the colour on a basic surface plot is function of the Z
data. they will either be faceted or interpolated but the contour3
function will not modify the colouring of the surf
object. The contour3
function only draws the isolines.
If you want your surface
to be coloured in a "blocky" way like a flat colour plot, you have to make the colormap "blocky" as well:
In your example you use 15
isolines, so you have to create a colormap with 15+1
colour so each colour block of the colormap match an isoline.
nContour = 15 ;
figure ; [X,Y,Z] = peaks(32);
surf(X,Y,Z, 'Edgecolor', 'none');
shading interp
colormap( parula(nContour+1) ) %// assign a colormap with only 15+1 colors
Will get you the image on the left of the screenshot below. Now add your isolines on top if you want:
hold on;
[C,h] = contour3(X,Y,Z,nContour,'k');
and you get the plot on the right. You can do both these things in no particular order, just make sure the colormap of the surface is adequate for the number of isolines you want.
Upvotes: 4