How to stack layers of 2D plot in horizontally instead of vertically?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have simple code which stacks 3 layers vertically but I am looking for a way that I can stack them horizontally or in other words along x/y axis and the code looks like as flows:
clear all;clc
x = -2:.1:2;
y = x;
z = rand(length(x),length(y));
for k = 1:15:length(z)
z1 = ones(size(z))*k+2;
surf(x,y,z1,abs(z))
hold on
end
xlim([-2.5 2.5])
ylim([-2.5 2.5])
zlim([-5 50])
set(gca,'Ydir','Normal');
colormap ('jet');
shading('flat');
댓글 수: 0
답변 (1개)
Walter Roberson
2015년 6월 8일
number_of_layers = 3;
relative_spacing = 0.1; %10%
x = -2:.1:2;
y = x;
z = rand(length(x),length(y),number_of_layers);
y_range = max(y)-min(y);
per_layer_offset = y_range * (1 + relative_spacing);
z1 = ones(size(z,1), size(z,2));
for k = 1:number_of_layers
this_y = y + (k-1) * per_layer_offset;
surf(x, this_y, z1, z(:,:,k));
hold on
end
xlim([-2.5 2.5]);
ylim([-2.5 max(this_y)]); %you will need to play with this
zlim([-5 5]); %whatever
댓글 수: 2
Walter Roberson
2015년 6월 8일
number_of_layers = 3;
X_spacing = 1.234; %adjust per tastes, 1 is valid
first_X = 0.5; %adjust per tastes, 1 is valid
x = -2:.1:2;
y = x;
nx = length(x);
ny = length(y);
z = rand(nx,ny,number_of_layers);
[Ycoord, Zcoord] = ndgrid(x, y);
for K = 1 : number_of_layers
Xcoord = (first_X + X_spacing * (K-1)) * ones(nx, ny);
surf(Xcoord, Ycoord, Zcoord, z(:,:,K));
hold on
end
ylim([-2.5 2.5]);
zlim([-2.5 2.5]);
and you will want to adjust the view.
You should also be considering creating a hgtransform as that would allow you to create your panes like you were originally, but then rotate them without rotating the axes.
You should also be thinking about using slice()
참고 항목
카테고리
Help Center 및 File Exchange에서 Map Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!