Effacer les filtres
Effacer les filtres

Conflict between background and graphics

2 vues (au cours des 30 derniers jours)
Jethro
Jethro le 13 Jan 2012
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...

Réponse acceptée

Chandra Kurniawan
Chandra Kurniawan le 15 Jan 2012
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 commentaires
Jethro
Jethro le 15 Jan 2012
Thank you so much, Chandra, it's the second time that you save my life with images lol!!
Chandra Kurniawan
Chandra Kurniawan le 15 Jan 2012
Glad to help you :D

Connectez-vous pour commenter.

Plus de réponses (4)

Image Analyst
Image Analyst le 13 Jan 2012
Perhaps this would interest you:
How do I add a background image to my GUI or figure window?
  2 commentaires
Jethro
Jethro le 14 Jan 2012
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 le 15 Jan 2012
Did you even try it?

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 14 Jan 2012
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 commentaires
Walter Roberson
Walter Roberson le 14 Jan 2012
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 le 14 Jan 2012
I have an axes for my background. On it I have another axes to set with graphs...

Connectez-vous pour commenter.


Chandra Kurniawan
Chandra Kurniawan le 15 Jan 2012
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 commentaire
Jethro
Jethro le 15 Jan 2012
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?

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 15 Jan 2012
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 commentaire
Lidank Abiel
Lidank Abiel le 6 Juin 2013
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by