Matlab, how to change the position of a contour plot along the z axis

I have a three-dimensional surface in my surf(x,y,z) shape surf(x,y,z)

I also have a contourf surface (which is basically a two-dimensional plane).

I draw them in one drawing, but the contourf graph contourf automatically at z=0 . I want to move the contourf graph to z=-10 (or any value along the z axis), but I cannot do this.

I am sure this is easy, but I cannot find the answer in MATLAB / Google help. Any ideas?

+6
source share
1 answer

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 does not work in HG2. It can be fixed using the hidden ContourZLevel outline ContourZLevel :

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

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

See another answer of mine for further explanation: plot multiple 2d graphic outlines on one 3D shape .

+9
source

Source: https://habr.com/ru/post/901053/


All Articles