Reputation: 627
I am plotting (for example three) different datasets using scatter
or plot
with the hold on
function consecutively. This generates a scatter plot with the last layer overlapping with all the other ones.
Is there a (plotting) function that can randomly disperse the layers?
Upvotes: 0
Views: 389
Reputation: 7423
One way you could achieve this is via a 3d plot.
Create a depth vector of the same length as your x & y vector with random numbers and plot using plot3 (instead of plot).
You can then use the command view(2) to change the viewpoint you will get the effect you are after.
Example
f1=figure;
f2=figure;
nValues = 2000;
for dataSet=1:3
r1 = rand(nValues,1);
r2 = rand(nValues,1);
r3 = rand(nValues,1);
t = r1 * pi * 2;
x = r2 .* cos(t) + r1(1);
y = r2 .* sin(t) + r2(1);
depth = r3;
set(0,'CurrentFigure',f1)
plot(x,y,'.', 'MarkerSize',25)
hold all
set(0,'CurrentFigure',f2)
plot3(x,y,depth,'.', 'MarkerSize',25)
hold all
end
% Change viewpoint
view(2)
Data plotted with plot command (distinct layers)
Data plotted with plot3 command using a random value for z (depth)
Upvotes: 2