How can I apply data labels to each point in a scatter plot in MATLAB 7.0.4 (R14SP2) ?
664 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 27 Juin 2009
Modifié(e) : MathWorks Support Team
le 20 Mai 2023
I want to apply different data labels to each point in a scatter plot. I want to be able to place a text of my choice next to each data point in the scatter plot.
Réponse acceptée
MathWorks Support Team
le 27 Juin 2009
You can apply different data labels to each point in a scatter plot by the use of the TEXT command. You can use the scatter plot data as input to the TEXT command with some additional displacement so that the text does not overlay the data points. A cell array should contain all the data labels as strings in cells corresponding to the data points. The following is an example:
x = 1:10; y = 1:10; scatter(x,y);
a = [1:10]'; b = num2str(a); c = cellstr(b);
dx = 0.1; dy = 0.1; % displacement so the text does not overlay the data points
text(x+dx, y+dy, c);
0 commentaires
Plus de réponses (1)
Adam Danz
le 8 Juin 2014
Modifié(e) : MathWorks Support Team
le 20 Mai 2023
For convenience, I've provided a function that labels desired points based on x and y values along with a string of labels. It works or numerical or text labels. It has additional parameters for positioning the label in reference to the data points (north, south, east etc) and has an option of adjusting axis limits if a data label is running off the plotted area.
0 commentaires
Voir également
Catégories
En savoir plus sur Scatter Plots 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!