I have a GUI with one object: axes and a pushbutton. When pressing the pushbutton, I would like to display on the axes several images. I tried to use subplots but it doesn’t seem to cope: the images go all over the GUI window and not just where the axes are.
Here is the code for my pushbutton:
axes(handles.ManyImage);
subplot(2,2,1);
RGB1 = imread('Image1.TIF');
imagesc(RGB1);
axis off
subplot(2,2,2);
RGB2 = imread('Image2.TIF');
imagesc(RGB2);
axis off
subplot(2,2,3);
RGB3 = imread('Image3.TIF');
imagesc(RGB3);
axis off
I attached the illustrations of my problem.
Thank you for the help!

댓글 수: 8

Try not turning off the axis
axis off
I don't think if that's the correct way of disappearing the axis.
Angelina
Angelina 2014년 8월 26일
Well, it adds the axis on each images. I would like my three images to stay within the axes I defined using the guide.
Ben11
Ben11 2014년 8월 26일
Are all of your images the same size?
Angelina
Angelina 2014년 8월 26일
Nope, they aren't. But still, they are partitinned equaly in the window.
Michael Haderlein
Michael Haderlein 2014년 8월 26일
편집: Michael Haderlein 2014년 8월 26일
Subplots are individual axes. You just created subplots (axes) on top of the first axes. They overlap, but they are not connected to each other. If you want axes inside a container, you can create a uipanel object and set the parent property of the axes (subplots) to the uipanel handle. As the positions are normalized by default, you can then just set the panel's position and the axis will follow.
Angelina
Angelina 2014년 8월 26일
Thanks Michael for your answer.
i used the uipanel object and created two axes (children of my uipanel object) and then displayed my images on each axes (only two images for now on, so one image per axes). Is it what you meant? As in, if I want x images in my uipanel object, I should create x different axes?
Cheers.
Yes, as far as I got your request, you want to have multiple images displayed but the axes should not be distributed all over the figure. Then create the uipanel, put it where you want, and put one axes per image into this panel.
Angelina
Angelina 2014년 8월 26일
Thanks!

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

 채택된 답변

Joseph Cheng
Joseph Cheng 2014년 8월 26일
편집: Joseph Cheng 2014년 8월 26일

0 개 추천

Well... depending on what you're attempting to do here is a sample pushbutton that you'll have to play around with the spacing.
to test this out create a blank gui and put only a push button and axes with their default tags. Size the axes1 appropriately and then paste this callback in. So for this method I use the the GUIDE's axes1 to figure out the position and the area for the subplots (which for a first pass couldn't think of a way to scale them properly for a generic function such that any MxN subplot layout would work).
Along with this method i believe the GUIDE axes1 is still preserved such that if you do need to do just 1 image and not the subplots then you can delete the handles.SubPlot axes and re-enable axes1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Sampimg{1} = rand(100);
Sampimg{2} = repmat(1:100,100,1);
Sampimg{3} = repmat([1:50 50:-1:1],100,1);
Sampimg{4} = repmat([1:50 50:-1:1]',100,1);
Sampimg{5} = rand(100);
Sampimg{6} = repmat(1:100,100,1);
Sampimg{7} = repmat([1:50 50:-1:1],100,1);
Sampimg{8} = repmat([1:50 50:-1:1]',100,1);
subplotMxN = [2 4];
Units = 'pixels';
set(handles.axes1,'units',Units );
Position = get(handles.axes1,'position');
ULPosition = [Position(1) Position(2)+Position(4) Position(3:4)];
set(handles.axes1,'Visible','off');
plotind = 1;
Vspacing = .1*Position(4);
Hspacing = .1*Position(3);
height = .6*Position(4)/subplotMxN(1);
width = .6*Position(3)/subplotMxN(2);
for Mind = 1:subplotMxN(1)
subVspacing = (Mind-1)*Vspacing;
subposRow = [ULPosition(1:2) 0 0] + [0 -subVspacing-Mind*height width height];
for Nind = 0:subplotMxN(2)-1
subHspacing = (Nind)*Hspacing;
if ~isfield(handles,'SubPlot')
handles.SubPlot(plotind) = axes;
elseif isfield(handles,'SubPlot') & length(handles.SubPlot)<prod(subplotMxN)
handles.SubPlot(plotind) = axes;
end
subpos = subposRow + [subHspacing+Nind*width 0 0 0];
set(handles.SubPlot(plotind),'units',Units)
set(handles.SubPlot(plotind),'Position',subpos)
imagesc(Sampimg{plotind});
plotind = plotind+1;
end
end
disp('debug')
guidata(hObject, handles);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

태그

질문:

2014년 8월 26일

편집:

2014년 8월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by