How can I add labels to my scatter plot?
286 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anne Bremer
le 14 Jan 2023
Commenté : Star Strider
le 14 Jan 2023
Hello Matlab experts,
I have problems adding data labels to each data point in my scatter plot. The labels I want to attach are in the first column in my Excelsheet. I would highly appreciate it if someone could help me. I am attaching the code below as well as my data file.
%load the data
t = readtable("dataset.xlsx");
x= t.Exp;
y= t.Sim;
sz=70;
s=scatter(x,y,sz,"filled")
hold on
a = [t.Name]'; b = num2str(a); c = cellstr(b);
dx = 0.1; dy = 0.1;
text(x+dx, y+dy, c, 'Fontsize', 10);
0 commentaires
Réponse acceptée
Star Strider
le 14 Jan 2023
Try something like this —
t = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1263190/dataset.xlsx')
x= t.Exp;
y= t.Sim;
sz=70;
s=scatter(x,y,sz,"filled");
xlabel('Exp')
ylabel('Sim')
text(x, y, t.Name, 'Vert','bottom', 'Horiz','left', 'FontSize',7)
set(gca, 'XScale','log', 'YScale','log')
I set the axis sclaes to 'log' to increase the separation between the points, and reduced the font size. I thought about rotating the labels, however I doubt that there is any way to avoid some of them overwriting the others.
.
6 commentaires
Star Strider
le 14 Jan 2023
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



