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.

Answers (2)

Torsten
Torsten on 18 Apr 2026 at 21:17
Edited: Torsten on 19 Apr 2026 at 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 on 18 Apr 2026 at 21:53
Edited: Matt J on 18 Apr 2026 at 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))

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Release

R2025b

Asked:

on 18 Apr 2026 at 20:38

Edited:

on 19 Apr 2026 at 11:02

Community Treasure Hunt

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

Start Hunting!