How to turn scatterplot labels on and off using uicontrol
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello dear matlabbers,
Now I would like to give the user of the code the possibility to turn the labels on and off. I appreciate any help and comments! Thanks a lot in advance!
So far my code looks like this:
x = rand(1,100); y = rand(1,100); pointsize = 30;
idx = repmat([1 : 10], 1, 10) % I used class memberships here
figure(1)
MDSnorm = scatter(x, y, pointsize, idx, 'filled');
dx = 0.015; dy = 0.015; % displacement so the text does not overlay the data points
T = text(x + dx, y +dy, labels);
colormap( jet ); % in my code I use a specific colormap
Button = uicontrol('Parent',figure(2),'Style','toggle','String',...
'labels','Units','normalized','Position',[0.8025 0.82 0.1 0.1],'Visible','on',...
'callback',{@pb_call, MDSnorm, ???});
At the end of my script I then tried to define the pb_call function. I tried out several different versions, they all failed. Unfortunately, I am not skilled enough to translate any tutorials to my specific problem.
I have a rough idea what I need to do...
function [] = pb_call( ??? )
if get(Button, 'Value')
T --> invisible % ???
else
T --> visible % ???
end
end
0 commentaires
Réponses (1)
Shubham Gupta
le 16 Oct 2019
Modifié(e) : Shubham Gupta
le 22 Oct 2019
Try the following method (it might work for you but there are some limitations) :
x = rand(1,100); y = rand(1,100); pointsize = 30;
idx = repmat([1 : 10], 1, 10) % I used class memberships here
figure(1)
MDSnorm = scatter(x, y, pointsize, idx, 'filled');
dx = 0.015; dy = 0.015; % displacement so the text does not overlay the data points
T = text(x + dx, y +dy, labels);
colormap( jet ); % in my code I use a specific colormap
Button = uicontrol('Parent',figure(2),'Style','toggle','String',...
'labels','Units','normalized','Position',[0.8025 0.82 0.1 0.1],'Visible','on',...
'callback',@pb_call);
And the function can be edited as follow:
function pb_call(src,event)
a = gcf; % get the handle for current figure
T = findobj(a,'type','text');
if src.Value == 1
set(T,'Visible','off')
else
set(T,'Visible','on')
end
end
Limitations:
Only works for the current figure ( maybe best if only 1 figure is opened)
Hope it helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!