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.

Respuestas (2)

Torsten
Torsten el 18 de Abr. de 2026 a las 21:17
Editada: Torsten el 19 de Abr. de 2026 a las 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 el 18 de Abr. de 2026 a las 21:53
Editada: Matt J el 18 de Abr. de 2026 a las 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))

Categorías

Más información sobre Graphics Object Programming en Centro de ayuda y File Exchange.

Productos

Versión

R2025b

Etiquetas

Preguntada:

el 18 de Abr. de 2026 a las 20:38

Editada:

el 19 de Abr. de 2026 a las 11:02

Community Treasure Hunt

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

Start Hunting!

Translated by