Make larger plot when mouse hover over subplot
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!