TextScatter implementation does not expose the indices it chose for display when 'TextDensityPercentage' is used

28 Ansichten (letzte 30 Tage)
rng(10) % for reproducibility
n=100;
x = randn(n,1);
y = randn(n,1);
seq = (1:n)';
h=textscatter(x,y,string(seq), ...
'TextDensityPercentage',20, ...
'DisplayName','text')
I want to know the indexes of the unis which have been displayed by function textscatter from handle h (in this case 1, 4 and 22) or from findall, ancestor, ....
I wanted to use textscatter with geoaxes but it seems it is not supported. Therefore the idea is to project the map on cartesian axes and then retrieve the indexes of displayed units from textscatter with 'Name', Value 'TextDensityPercentage',20, but I need to know the indexes.
Any other idea is welcome (apart from "implementing my own label-selection rule" which labels points if they are not closer than a threshold) .
Copilot and ChatGPT claim it is not possible but I want to have your opinion.
Thank you in advance

Antworten (1)

Yashwanth
Yashwanth am 16 Jan. 2026 um 6:34
Hi Marco,
You can give a try on recovering the indices via label text, since your labels are the indices themselves, you can
  • Extract the displayed text strings
  • Convert them back to numbers
  • Those numbers are the indices
Please refer to the code section for implementation.
txtHandles = findall(h, 'Type', 'Text');
displayedLabels = string({txtHandles.String});
displayedIdx = str2double(displayedLabels);
displayedIdx = sort(displayedIdx);
  2 Kommentare
Marco Riani
Marco Riani am 17 Jan. 2026 um 8:09
Dear Yashwanth thank you very much.
this is indeed the first solution we tried and it works witht the labels created by function text but does not work with the labels produced by textscatter
Thanks again
Marco Riani
Marco Riani am 17 Jan. 2026 um 8:12
In other words
rng(10) % for reproducibility
n=100;
x = randn(n,1);
y = randn(n,1);
seq = (1:n)';
h=textscatter(x,y,string(seq), ...
'TextDensityPercentage',20, ...
'DisplayName','text');
txtHandles = findall(h, 'Type', 'Text');
% txtHandles is empty
disp(txtHandles)
0×0 empty GraphicsPlaceholder array.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Phased Array Design and Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by