Graph of several 2d contour plots in one three-dimensional figure [Matlab]

I would like to know how to build several 2D graphs located at a distance from the z axis in a three-dimensional drawing:

blah

+4
source share
1 answer

NOTE The first part of this answer was for HG1 graphics. See Part Two if you are working with MATLAB R2014b or later ( HG2 ).


HG1:

The contour function internally creates the patch series and returns them as a combined hggroup object . Thus, we could set the ZData all patches by moving the Z-sizes to the desired level (by default, the path is displayed at z = 0).

Here is an example:

 [X,Y,Z] = peaks; surf(X, Y, Z), hold on % plot surface [~,h] = contour(X,Y,Z,20); % plot contour at the bottom set_contour_z_level(h, -9) [~,h] = contour(X,Y,Z,20); % plot contour at the top set_contour_z_level(h, +9) hold off view(3); axis vis3d; grid on 

multiple_contour_plots

Here is the code for the set_contour_z_level function used above:

 function set_contour_z_level(h, zlevel) % check that we got the correct kind of graphics handle assert(isa(handle(h), 'specgraph.contourgroup'), ... 'Expecting a handle returned by contour/contour3'); assert(isscalar(zlevel)); % handle encapsulates a bunch of child patch objects % with ZData set to empty matrix hh = get(h, 'Children'); for i=1:numel(hh) ZData = get(hh(i), 'XData'); % get matrix shape ZData(:) = zlevel; % fill it with constant Z value set(hh(i), 'ZData',ZData); % update patch end end 

HG2:

The above solution no longer works starting with R2014b. In HG2, path objects no longer have graphical objects as children ( Why is the property "Empty" for some objects? ).

Fortunately, there is an easy fix with the hidden ContourZLevel contour ContourZLevel . You can find out more undocumented outline graph settings here and here .

So the previous example just becomes:

 [X,Y,Z] = peaks; surf(X, Y, Z), hold on % plot surface [~,h] = contour(X,Y,Z,20); % plot contour at the bottom h.ContourZLevel = -9; [~,h] = contour(X,Y,Z,20); % plot contour at the top h.ContourZLevel = +9; hold off view(3); axis vis3d; grid on 

contours


Another solution that works in all versions will be the "parent" outline of the hgtransform object and convert it using simple z-translation . Something like that:

 t = hgtransform('Parent',gca); [~,h] = contour(X,Y,Z,20, 'Parent',t); set(t, 'Matrix',makehgtform('translate',[0 0 9])); 
+6
source

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


All Articles