How to add data labels for scatter3 plot

조회 수: 27 (최근 30일)
Masoud Taleb
Masoud Taleb 2022년 5월 31일
댓글: Masoud Taleb 2022년 5월 31일
Hello Matlab experts
I have a problem with my scatter plot. I can not add labels to the data points! I put my code below and attach the data file as well. The column 1 of my data file should be apear as the labels; but I failed to add them. I appreciate if someone can help me with it.
clear all
clc
A=readmatrix('dataset.csv');
% Make unit sphere
[x,y,z] = sphere;
% Scale to desire radius.
radius = 2500000;
x = x*radius;
y = y*radius;
z = z*radius;
% Translate sphere to new location.
offset = 0;
% Plot as surface.
surf(x+offset,y+offset,z+offset)
shading interp
alpha(0.15)
% Label axes.
xlabel('S1', 'FontSize', 10);
ylabel('S2', 'FontSize', 10);
zlabel('S3', 'FontSize', 10);
hold on
% Plot scatter.
scatter3(A(:,2),A(:,3),A(:,4),'filled');
hAxis = gca;
hAxis.XRuler.FirstCrossoverValue = 0; % X crossover with Y axis
hAxis.XRuler.SecondCrossoverValue = 0; % X crossover with Z axis
hAxis.YRuler.FirstCrossoverValue = 0; % Y crossover with X axis
hAxis.YRuler.SecondCrossoverValue = 0; % Y crossover with Z axis
hAxis.ZRuler.FirstCrossoverValue = 0; % Z crossover with X axis
hAxis.ZRuler.SecondCrossoverValue = 0; % Z crossover with Y axis
% grid off
set(gca,'XTicklabel',[]);
set(gca,'YTicklabel',[]);
set(gca,'ZTicklabel',[]);
axis equal;

채택된 답변

KSSV
KSSV 2022년 5월 31일
Read about text
A=readmatrix('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1017090/dataset.csv');
% Make unit sphere
[x,y,z] = sphere;
% Scale to desire radius.
radius = 2500000;
x = x*radius;
y = y*radius;
z = z*radius;
% Translate sphere to new location.
offset = 0;
% Plot as surface.
surf(x+offset,y+offset,z+offset)
shading interp
alpha(0.15)
% Label axes.
xlabel('S1', 'FontSize', 10);
ylabel('S2', 'FontSize', 10);
zlabel('S3', 'FontSize', 10);
hold on
% Plot scatter.
scatter3(A(:,2),A(:,3),A(:,4),'filled');
text(A(:,2),A(:,3),A(:,4),num2str(A(:,1))) %<---- play with this
hAxis = gca;
hAxis.XRuler.FirstCrossoverValue = 0; % X crossover with Y axis
hAxis.XRuler.SecondCrossoverValue = 0; % X crossover with Z axis
hAxis.YRuler.FirstCrossoverValue = 0; % Y crossover with X axis
hAxis.YRuler.SecondCrossoverValue = 0; % Y crossover with Z axis
hAxis.ZRuler.FirstCrossoverValue = 0; % Z crossover with X axis
hAxis.ZRuler.SecondCrossoverValue = 0; % Z crossover with Y axis
% grid off
set(gca,'XTicklabel',[]);
set(gca,'YTicklabel',[]);
set(gca,'ZTicklabel',[]);
axis equal;
  댓글 수: 1
Masoud Taleb
Masoud Taleb 2022년 5월 31일
Yes, this is exactly what I wanted. Thanks @KSSV

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by