Take an example, I have 2 a sequences of left and right images: left01, right01, left02, right02, etc. How can I display those on only two figures: left and right. Each loop, these 2 figures will be updated with leftxx and rightxx.
"Hold on" will only hold the current figure. Creating figures with figure('Name', 'Left') will not do the trick, as multiple "Left" figures will be created. Yet imshow() does not let me specify the figure to display based on its name.
What I want is something similar to OpenCV, which let you choose which figure (already opened) to display
cvNamedWindow("Left");
cvShowImage("Left", myLeftImg);
"Left" figure will be updated with new img without creating new figure.
Thanks a lot.
Ken.
You need to save a handle on the axes-object within the figure and you need to tell the image-function to precisely which axes you want it to draw.
Try something along the lines of:
figure, h_r = axes;
figure, h_l = axes;
for n=1:whatever
image(right_bitmap, 'Parent', h_r, ...);
image(left_bitmap, 'Parent', h_l, ...);
drawnow;
end;
Update: image expects the handle as property 'Parent' rather than as first parameter.
Related
I created a bank figure using GUIDE and put an axes object inside it and saved the figure. Now I want to load the figure and set its axes as current axes object. This is my code:
close all; clear all; clc;
fh = openfig('test.fig');
ah = findobj(fh, 'tag', 'axes1');
figure(fh);
axes(ah);
plot(rand(10, 1));
But plot creates a new figure and plots in it! Am I missing something?
I know that I can solve it with plot(ah, ...), but I want to make gca to return this new axes. I have a lot of plotting codes that I want to be drawn in this new axes.
By default, HandleVisibility of GUIDE figures is set such that they aren't automatically detected. For example if you load the figure and then call gcf, you'll also create a new figure.
To have the plot be placed within the axes, you can specify the axes explicitly as the parent of the plot command.
plot(rand(10, 1), 'Parent', ah)
Alternately, you could specify that the HandleVisibility of the figure is 'on'. And then plot will be able to find it. This could be done by either setting the value of HandleVisibility using the property editor in GUIDE or calling the set function:
set(fh, 'HandleVisibility', 'on')
I recommend the first option as explicitly specifying the parent axes is always better than implicit.
I croped some parts of images and displayed them in one figure with subplots. Number of subplots are not certain. I read images from a file then crop them. My aim is that when I click or double click on an subplot, I want to see whole image in new figure.
I want to give an example just to make clear my question. if I click on first subplot, I want to see whole cameraman image in new figure.
Is it possible? If it is possible, What is the way?
The example uses the ButtonDownFcn that can be added to most matlab plot commands.
Just copy both functions into one file and run the "interactivePlot" function.
The list_of_images contains all matrices that shall be plotted.
The number of matrices is flexible. However, you have to adjust the subplot command...
function interactivePlot
list_of_images = {rand(5), rand(10), rand(50), rand(100)}
for ii = 1:length(list_of_images)
subplot(2,2,ii)
imagesc(list_of_images{ii}, 'ButtonDownFcn', #newFigure1)
end
end
function newFigure1(h1, h2)
figure()
data = get(h1, 'CData');
imagesc(data)
end
I had same problem, change your function like below then it will be solved:
function newFigure1(h1, h2)
figure()
data = get(h1, 'CData');
colormap(gray);
imagesc(data)
end
Hi , I want to save this image produced from imagesc(magic(3)), the exact rainbow representation, is it possible?
Thanks.
This question might look like a duplicate , but it is not . I looked at the solution to the similar question at this site , but it did not satisfy me .
I have looked into the Matlab help center and the close answer that I got was this one , at the bottom of http://goo.gl/p907wR
To save the figure as a file (don't matter how it was created), one should do:
saveas(figureHandle,'filename','format')
where figureHandle could be the gcf handle, which means: get current figure.
As pointed in the discussion, if someone doesn't want the ticks to be shown, the person can add:
set(gca,'XTick',[])
set(gca,'YTick',[])
where gca is the handle to the current axis, just as gcf. If you have more than one axis, don't forget to "handle the handles". They are returned to you when you create them, i.e.:
hFig = figure(pairValuedProperties); % Create and get the figure handle
hAxes1 = suplot(2,1,1,pairValuedProperties); % Create and get the upper axes handle
hAxes2 = suplot(2,1,2,pairValuedProperties); % Create and get the bottom axes handle
where the pair value are the figure or axes properties declared in the following syntax:
'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,…
Here are the matlab documentation about the Figure and Axes Properties, and about the saveas method.
Example:
The image saved with the following code:
figure
imagesc(magic(3))
set(gca,'XTick',[]) % Remove the ticks in the x axis!
set(gca,'YTick',[]) % Remove the ticks in the y axis
set(gca,'Position',[0 0 1 1]) % Make the axes occupy the hole figure
saveas(gcf,'Figure','png')
You can use:
print -djpeg99 'foo.jpg'
This will save it as 'foo.jpg' as you need.
You can use the following code
imagesc(A);
%%saving the image
hgexport(gcf, 'figure1.jpg', hgexport('factorystyle'), 'Format', 'jpeg');
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4 4]);
print -djpeg filename.jpg -r10
Here A will be the matrix from which you will have an image. And the image will be saved as filename.jpg in the directory.
I draw images to axes in my matlab UI, but I don't want the axes and ticks to be visible how do I prevent that, and also where do I make this call?
I do this
imagesc(myImage,'parent',handles.axesInGuide);
axis off;
Is this what you are looking for?
This is definitely somewhere else on this website and in the matlab documentation. Try typing
help plot
Or using the documentation on plotting!
edit: Now that you have shown what you are doing. (You don't need the handles, I just always write them in to clutter my workspace)
myImage = yurbuds0x2Dironman; # don't ask
fH = figure;
iH = imagesc(myImage);
set(gca,'xtick',[],'ytick',[])
Are you able to do it like this?
I support the
set(gca,'xtick',[],'ytick',[]);
approach over the
axis off
one. The reason is set(gca, ...) just removes the labels but keeps the axes, unlike axis off. I am generating a group of images with fixed dimensions to combine later into a video. Deleting the axes creates different size frames that can't be recombined.
Usually when I plot in MATLAB, it always draws on the same figure. How do I make it draw in a new figure?
I know it is pretty elementary, but I'm not finding it using Google Search.
figure;
plot(something);
or
figure(2);
plot(something);
...
figure(3);
plot(something else);
...
etc.
While doing "figure(1), figure(2),..." will solve the problem in most cases, it will not solve them in all cases. Suppose you have a bunch of MATLAB figures on your desktop and how many you have open varies from time to time before you run your code. Using the answers provided, you will overwrite these figures, which you may not want. The easy workaround is to just use the command "figure" before you plot.
Example: you have five figures on your desktop from a previous script you ran and you use
figure(1);
plot(...)
figure(2);
plot(...)
You just plotted over the figures on your desktop. However the code
figure;
plot(...)
figure;
plot(...)
just created figures 6 and 7 with your desired plots and left your previous plots 1-5 alone.
The other thing to be careful about, is to use the clf (clear figure) command when you are starting a fresh plot. Otherwise you may be plotting on a pre-existing figure (not possible with the figure command by itself, but if you do figure(2) there may already be a figure #2), with more than one axis, or an axis that is placed kinda funny. Use clf to ensure that you're starting from scratch:
figure(N);
clf;
plot(something);
...
As has already been said: figure will create a new figure for your next plots. While calling figure you can also configure it. Example:
figHandle = figure('Name', 'Name of Figure', 'OuterPosition',[1, 1, scrsz(3), scrsz(4)]);
The example sets the name for the window and the outer size of it in relation to the used screen.
Here figHandle is the handle to the resulting figure and can be used later to change appearance and content. Examples:
Dot notation:
figHandle.PaperOrientation = 'portrait';
figHandle.PaperUnits = 'centimeters';
Old Style:
set(figHandle, 'PaperOrientation', 'portrait', 'PaperUnits', 'centimeters');
Using the handle with dot notation or set, options for printing are configured here.
By keeping the handles for the figures with distinc names you can interact with multiple active figures. To set a existing figure as your active, call figure(figHandle). New plots will go there now.
Another common option is when you do want multiple plots in a single window
f = figure;
hold on
plot(x1,y1)
plot(x2,y2)
...
plots multiple data sets on the same (new) figure.
As simple as this-
figure, plot(yourfigure);