Conflict between background and graphics

1 次查看(过去 30 天)
Hi everybody! I'm using gui matlab to create interfaces. I set a background using axes, and now I have to add a pushbutton that show me a graphic in an other axes space, but when I push it, the graphic appears on my background, even if I correctly set my handles...
I think I need to "lock" my background axes... Or, there're any other solutions?? Can anyone help me?
This is my background code...
function sfondo3_CreateFcn(hObject, eventdata, handles)
axes(hObject)
imshow('image.png');
EDIT 1 14/01/2012 - 01.45 (European Time)
I already have my background image... This is a screenshot of my figure:
I already have my "background axes", set with a background image. When I set a pushbutton's handles that must make me appear a graph, it appears on the background, and not in "axes 2" space...
I want it appears in "Axes 2" without change my background settings...

采纳的回答

Chandra Kurniawan
Chandra Kurniawan 2012-1-15
Hi, Jethro
Just use the same concept.
No matter if you want to plot something in second axes instead of display an image.
Here the example :
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes2);
x = -pi:.1:pi;
y = sin(x);
plot(x,y,'ro','linewidth',2);
axis off
guidata(hObject, handles);
%
  2 个评论
Jethro
Jethro 2012-1-15
Thank you so much, Chandra, it's the second time that you save my life with images lol!!

请先登录,再进行评论。

更多回答(4 个)

Image Analyst
Image Analyst 2012-1-13
Perhaps this would interest you:
How do I add a background image to my GUI or figure window?
  2 个评论
Jethro
Jethro 2012-1-14
I already have my background image...
This is a screenshot of my figure:
http://img221.imageshack.us/img221/2784/imghm.png
Look it: I already have my "background axes". When I set a pushbutton's handles that must make me appear a graph, it appears on the background, and not in "axes 2" space...
There's anyone who can help me??

请先登录,再进行评论。


Image Analyst
Image Analyst 2012-1-14
call
axes(handles.G1_grafico);
before you call anything like plot(), imshow(), bar(), etc. That will set the current axes to G1_grafico. It will remain that unless you shift focus to some other axes, such as displaying another image in your background axes.
  5 个评论
Walter Roberson
Walter Roberson 2012-1-14
How is your graph space defined? An axes can be the child of a figure or a uipanel, but not the child of another axes.
If you have a blank area in a figure that you wish to draw in, then you can set f to the figure number, and when you create az you can give a Position property (and possibly a Units property) to place it at a particular location on the figure.
Jethro
Jethro 2012-1-14
I have an axes for my background. On it I have another axes to set with graphs...

请先登录,再进行评论。


Chandra Kurniawan
Chandra Kurniawan 2012-1-15
Hi, Jethro
Looks like your problem is almost similar to this one :
What is function sfondo3_CreateFcn?
Is it same with function Background_LAN_CreateFcn in your old question?
Why you should make this to set your background?
Would not it be better if you use OpeningFcn to set your background?
Eq :
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
I = imread('pears.png');
axes(handles.axes1);
imshow(I);
guidata(hObject, handles);
I just create my own GUI with my own concept and it works just fine.
THE CODE
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else gui_mainfcn(gui_State, varargin{:}); end
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
I = imread('pears.png');
axes(handles.axes1);
imshow(I);
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
J = imread('football.jpg');
axes(handles.axes2);
imshow(J);
guidata(hObject, handles);
  1 个评论
Jethro
Jethro 2012-1-15
Yes, my problem it's similar to this one, and yes, "function background..." and "sfondo_3" are the same things...
My problem it's a bit different, because instead of the second image, 'football.jpg', I have to generate plots starting by statistics I have :)
Can you help me?

请先登录,再进行评论。


Image Analyst
Image Analyst 2012-1-15
Jethro: Did you even try the code that was in the link I gave earlier? It shows a plot over an image. Here, let me reproduce it for you below and then you can say if that is similar enough to what you want to do such that you can adapt it to your situation:
close all;
% This creates the 'background' axes
ha = axes('units','normalized', ...
'position',[0 0 1 1]);
% Move the background axes to the bottom
uistack(ha,'bottom');
% Load in a background image and display it using the correct colors
% The image used below, is in the Image Processing Toolbox. If you do not have %access to this toolbox, you can use another image file instead.
I=imread('eight.tif');
hi = imagesc(I)
colormap gray
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(ha,'handlevisibility','off', ...
'visible','off')
% Now we can use the figure, as required.
% For example, we can put a plot in an axes
axes('position',[0.3,0.35,0.4,0.4])
plot(rand(10))
  1 个评论
Lidank Abiel
Lidank Abiel 2013-6-6
I have the same problem and i use that code. it work to display my image as background, but when i browse another image, my background change become the image that i browse.
here my code:
function tes2_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
ha = axes('units','normalized','position',[0 0 1 1]);
uistack(ha,'bottom');
[back map] = imread('Marilyn-Monroe-22388.jpg');
image(back)
colormap (map)
set(ha,'handlevisibility','off','visible','off')
function Open_Callback(hObject, eventdata, handles)
global citra
try
[filename, foldername] = uigetfile('*.jpg');
if filename ~= 0
FileName = fullfile(foldername, filename);
end
citra = imread(FileName);
imshow(citra, []);
end
handles.citra=citra;
guidata(hObject,handles);
thanks before

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by