How to add data labels for scatter3 plot
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Masoud Taleb
am 31 Mai 2022
Kommentiert: Masoud Taleb
am 31 Mai 2022
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;
0 Kommentare
Akzeptierte Antwort
KSSV
am 31 Mai 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;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
