Defining scatter plot with different 'markers' & 'colors'

조회 수: 3 (최근 30일)
kenneth lee
kenneth lee 2020년 2월 23일
댓글: Rik 2020년 3월 13일
Hi i am plotting a 3D scatter plot however i have to mark all 12 different classes on the 4th colomun in the attached file with 12 different markers and colors. Is there a way to randomize the 12 colors and markers all do i have to define them one by one? l only know how to do up till the 3d plot. Thanks in advance! :)
function plot3Ddata(x,y,z)
test = xlsread('HQ3.xlsx', 'A2:C223');
x=test(:,1);
y=test(:,2);
z=test(:,3);
scatter3(x,y,z);
end
the above code is my code for now...

채택된 답변

Rik
Rik 2020년 2월 23일
This should be close to what you need:
test = xlsread('HQ3.xlsx', 'A2:D223');
x=test(:,1);
y=test(:,2);
z=test(:,3);
groups=test(:,4);
figure(1),clf(1)
for g=1:max(groups)
L=groups==g;
scatter3(x(L),y(L),z(L),...
'DisplayName',sprintf('group %d',g));
hold on
end
hold off
legend
  댓글 수: 3
kenneth lee
kenneth lee 2020년 3월 13일
Hi so sorry for the late response, but is there a possibility to make all of them with different shapes and colors as i wan to distinctively reseperate them for better visualisation. Thanks alot for the follow up, really appreciate it! :)
Rik
Rik 2020년 3월 13일
If you don't want circles you can use plot3 instead of scatter3. Then you can set the LineSpec to whatever spec you like.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by