grouping 2D data for scatter plot matlab

时间:2018-03-13 15:10:27

标签: matlab scatter-plot

I have the example of the data below

a=[1,12;2,18;3,20];
b=[2,13;7,16;3,27; 4,22];
c=[7,23;2,13;8,18;3,15; 4,13];

Result=vertcat(a,b,c);
figure, scatter(Result(2,:), (Result(1,:))
xlabel('age')
ylabel('index')

This code provides me a plot of all the sample in an overall view, but I would like to show the result of each group of a, b,c ( with different size) in the same panel with different markers.

I look through MATLAB doc they have a example of gscatter but I did not understood how I can group the data to be able to present in it in the panel such as what you see below ( this panel is only an example how my figure should like and is a copy and paste only)

enter image description here

any help is highly appriciated

1 个答案:

答案 0 :(得分:2)

只是分别绘制每种颜色,可能是最简单的选择:

a=[1,12;2,18;3,20];
b=[2,13;7,16;3,27; 4,22];
c=[7,23;2,13;8,18;3,15; 4,13];

figure, 
hold on
scatter(a(:,1),a(:,2),'g','filled')
scatter(b(:,1),b(:,2),'b','filled')
scatter(c(:,1),c(:,2),'r','filled')

grid on
xlabel('age')
ylabel('index')

enter image description here