How to draw a figure with subplots which can pop up in a new window when I click at them?

조회 수: 16 (최근 30일)
Hi,all. How can we draw such a figure in which if you click at a subplot of the figure, that subplot will get enlarged and pop up in new figure window? What function shall be employed? Suppose we had a figure with 12 subplots, and if you click at any of the subplots, that subplots will be magnified and pop up in a new window. How can we make that? Thank you!

채택된 답변

emehmetcik
emehmetcik 2015년 2월 15일
Hi,
A simple way to do this is to use the button press callback function (ButtonDownFcn):
Here is an example:
clear
close all
clc
x1 = 1 : 10;
y1 = randn(1, 10);
x2 = randn(10);
y2 = randn(10);
figure;
h1 = subplot(2, 1, 1);
plot(x1, y1);
h2 = subplot(2, 1, 2);
plot(x2, y2)
set(h1, 'ButtonDownFcn', {'PlotNewFigure', x1, y1, 123})
set(h2, 'ButtonDownFcn', {'PlotNewFigure', x2, y2, 456})
PlotNewFigure that I used in this code is a seperate function (saved in another m file).
function PlotNewFigure(varargin)
figure(varargin{5});
plot(varargin{3}, varargin{4})
end
  댓글 수: 6
William
William 2015년 2월 19일
Thank you again!I understand it now with your help.
Shawn Fernandes
Shawn Fernandes 2017년 2월 19일
Hi,
The above solution is working for plot, but not working for imshow matrix, PFB code.
function PlotNewFigure(varargin)
if(varargin{6}==0)
figure(varargin{5});
plot(varargin{3}, varargin{4})
end
if(varargin{6}==1)
figure(varargin{5});
imshow(varargin{3})
end
if(varargin{6}==2)
figure(varargin{5});
imshow(varargin{3},jet(varargin{4}))
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

maycon moreira
maycon moreira 2018년 4월 20일
Hi,
I can not apply the same method in my code, how do I do that?
A=imread('cam.png'); subplot(4,3,1) imshow(A) title('Image A'); B=imread('futurama.jpg'); subplot(4,3,2) imshow(B) title ('Image B');

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by