Make larger plot when mouse hover over subplot

조회 수: 2(최근 30일)
Etienne Coetzee
Etienne Coetzee 2018년 10월 9일
편집: jonas 2018년 10월 9일
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

채택된 답변

jonas
jonas 2018년 10월 9일
편집: jonas 2018년 10월 9일
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개)

범주

Find more on Graphics Object Programming 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!

Translated by