How do I plot different x-y plots stacked one behind another in MATLAB?
8 views (last 30 days)
Show older comments
I have two 2-D plots that I would like to stack, one behind the other, to form a 3-D plot.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
You can achieve this by using the PLOT3 function in MATLAB, with different Y-dimensional offsets for each 2-D plot. For example,
% Data
x{1} = (.2:.2:2).';
z{1} = rand(10,1);
x{2} = 1:4;
z{2} = randn(4,1);
% Plotting
figure;
hold on;
for i = 1:length(x)
plot3(x{i}, i*ones(size(x{i})), z{i});
end
hold off;
grid on;
set(gca,'CameraPosition',[-19 -5 5]);
set(gca,'CameraViewAngle',8);
You can also add semi-transparent patches to each plane to distinguish each 2-D plot. Note that this will change the renderer to OpenGL.
axlim = axis;
for i = 1:length(x)
patch(axlim([1 1 2 2]), [i i i i], axlim([5 6 6 5]), [.8 .9 .8], 'FaceAlpha', .4);
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!