How do I plot different x-y plots stacked one behind another in MATLAB?

I have two 2-D plots that I would like to stack, one behind the other, to form a 3-D plot.

 Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by