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!