ChanChow
ChanChow

Reputation: 1366

How can I plot multiple 3D arrays on a single plot?

I have multiple arrays of 3D data. How can I plot them all on a single plot? The size of the arrays are not equal.

For example:

array1_xy = [1 2;3 4;5 6]
array1_z = [10;20;30]
array2_xy = [2 4;5 6;4 6;4 5]
array2_z = [10;20;50;10]
array3_xy = [1 4;1 6;1 3;1 5;1 1;3 4]
array3_z = [10;20;30;10;80;30]

How can I plot them on a single 3D plot with different markers?

Upvotes: 1

Views: 3249

Answers (2)

Maroun
Maroun

Reputation: 95968

You want the hold function.

From the link above:

x = -pi:pi/20:pi;
plot(sin(x))
hold on
plot(cos(x))
hold off

This will plot sin(x) and on the same axes it'll plot cos(x).

If you want to plot your arrays with plot3 function, you can still use hold on; and plot them in the same graph.

Upvotes: 1

Sida Zhou
Sida Zhou

Reputation: 3705

I assume you want to do a xyz scatter plot(?) in that case, use plot3. Details go help plot3 Details about markers, go help plot

Follow code does what you want.

plot3(array1_xy(:,1),array1_xy(:,2),array1_z,'x'); hold on;
plot3(array2_xy(:,1),array2_xy(:,2),array2_z,'o'); 
plot3(array3_xy(:,1),array3_xy(:,2),array3_z,'p'); 

Upvotes: 0

Related Questions