TextScatter implementation does not expose the indices it chose for display when 'TextDensityPercentage' is used
Show older comments
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
Answers (1)
Yashwanth
on 16 Jan 2026
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);
Categories
Find more on Phased Array Design and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
