textscatter example, and behavior, is mysterious

The code for the textscatter example at
looks like it should produce text at those random points. Instead the figure there shows some text in unusual places, some points that dont belong to any specific label, and in general, the whole thing is mysterious.

Réponses (2)

Torsten
Torsten le 18 Avr 2026 à 21:17
Modifié(e) : Torsten le 19 Avr 2026 à 11:02
Most probably, text is set where possible and the rest positions are marked by blue points.
The following example seems to support this:
rng("default")
n = 11;
x = rand(n,1);
y = rand(n,1);
str = string(1:n);
figure
textscatter(x,y,str);
% Print positions of str(6) and str(9) which is not shown
[x(6),y(6)]
ans = 1×2
0.0975 0.4218
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[x(9),y(9)]
ans = 1×2
0.9575 0.9595
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Info from AI:
Key Features and Behaviors
  • Automatic Readability: By default, textscatter may not display all input words to avoid overcrowding, replacing less important labels with markers.
  • Data Density Management: The TextDensityPercentage parameter controls what percentage of text data is displayed (default is 60%).
So to plot all text markers in the above example, you could use
textscatter(x,y,str,'TextDensityPercentage',100);
Matt J
Matt J le 18 Avr 2026 à 21:53
Modifié(e) : Matt J le 18 Avr 2026 à 21:55
Here's an alternative, whose behavior you might like better:
rng("default")
n = 11;
x = rand(n,1);
y = rand(n,1);
str = string(1:n);
figure
H=scatter(x,y,'.');
scatlabel(H,string(1:n))

Catégories

En savoir plus sur Graphics Object Programming dans Centre d'aide et File Exchange

Produits

Version

R2025b

Question posée :

le 18 Avr 2026 à 20:38

Modifié(e) :

le 19 Avr 2026 à 11:02

Community Treasure Hunt

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

Start Hunting!

Translated by