Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab how to change contourf plot's location on z axis

I have a 3d surface in my figure surf(x,y,z)

I also have a contourf surface (which is basically a 2D plane).

I plot them in the same figure but the contourf plot is automatically at z=0 level. I want to move the contourf plot to z=-10 (or any value on z-axis) but I can't do it.

I am sure it is easy but I can't find the answer in MATLAB help/Google. Any ideas?

like image 480
theenemy Avatar asked Nov 08 '11 17:11

theenemy


People also ask

How do you set contour levels in Matlab?

To draw the contour lines at specific heights, specify levels as a vector of monotonically increasing values. To draw the contours at one height ( k ), specify levels as a two-element row vector [k k] . contour(___, LineSpec ) specifies the style and color of the contour lines.

How do you plot a level surface in Matlab?

surf( X , Y , Z ) creates a three-dimensional surface plot, which is a three-dimensional surface that has solid edge colors and solid face colors. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y .

How do you smooth contour in Matlab?

Choose the "smoothness" of the new plot via the parameter newpoints . A 3D-surf plot would be more suitable for very smooth color-shading. Just rotate it to a top-down view.

What kind of plot does the Surfc function produce?

surfc( Z ) creates a surface and contour plot and uses the column and row indices of the elements in Z as the x- and y -coordinates.


1 Answers

Consider the following example:

%# plot surface and contour
Z = peaks;
surf(Z), hold on
[~,h] = contourf(Z);       %# get handle to contourgroup object

%# change the ZData property of the inner patches
hh = get(h,'Children');    %# get handles to patch objects
for i=1:numel(hh)
    zdata = ones(size( get(hh(i),'XData') ));
    set(hh(i), 'ZData',-10*zdata)
end

screenshot


UPDATE:

The above doesn't work anymore in HG2. It can be fixed using a hidden property of contours ContourZLevel:

Z = peaks;
surf(Z), hold on
[~,h] = contourf(Z);
h.ContourZLevel = -10;

You can also use hgtransform to achieve a similar thing, which is the documented and recommended approach.

See another answer of mine for further explanation: plot multiple 2d contour plots in one 3d figure.

like image 181
Amro Avatar answered Sep 30 '22 02:09

Amro