How to turn scatterplot labels on and off using uicontrol
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Shubham Gupta
am 16 Okt. 2019
Bearbeitet: Shubham Gupta
am 22 Okt. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!