MATLAB Answers

0

Make larger plot when mouse hover over subplot

Asked by Etienne Coetzee on 9 Oct 2018
Latest activity Edited by jonas
on 9 Oct 2018
Hi All
I have a subplot of 8 x 8 parameters. I would like to implement a feature where a larger plot appears of the subplot I am hovering over with the mouse. I would prefer not to have to click the mouse. I am not sure how to implement this because I noticed some other posts mentioning that it is not possible to find axes handles in panels. Any help would be appreciated.
Regards
Etienne

  0 Comments

Sign in to comment.

Products

1 Answer

Answer by jonas
on 9 Oct 2018
Edited by jonas
on 9 Oct 2018
 Accepted Answer

I wrote a little demo for how you can program this using callbacks. The reason I wrote it is because I am trying to learn callbacks, so I am by no means an expert :)
The current callback function is quite costly, but it works!
figure;
set(gcf,'units','normalized')
% Some dummy plots
for i=1:9
ax{i}=subplot(3,3,i)
plot(rand(10,10))
end
% Get axes position and convert to polygons
pos = get([ax{:}],'position')
poly = cellfun(@(x)[x(1),x(1)+x(3),x(1)+x(3),x(1);x(2),x(2),x(2)+x(4),x(2)+x(4)],pos,'uniformoutput',false)
% Initiate callback
set(gcf,'WindowButtonMotionFcn',{@FigCallback,poly,pos,ax})
% Callback function
function FigCallback(scr,evnt,poly,pos,ax,~)
C = get(gcf, 'CurrentPoint');
in = cellfun(@(x)inpolygon(C(1),C(2),x(1,:)',x(2,:)'),poly)
if sum(in)>0
sum(in)
set(ax{in},'Position',pos{in}.*[.8 .8 1.2 1.2])
uistack(ax{in},'top')
else
cellfun(@(x,y)set(x,'position',y),ax',pos)
end
end

  0 Comments

Sign in to comment.