How to add data labels for scatter3 plot

89 views (last 30 days)
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;

Accepted Answer

KSSV
KSSV on 31 May 2022
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;

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!