Generating the plots on the same figure using image command.

I am generating the plots using image command in matlab that is image(x,y,Z). Unlike plot command which we can do a "hold on" to generate the plots on the same figure, it seems we cannot do with the image command.
I am running a loop in which every loop generates a figure from the image command, I want to generate the plots on the same figure(using the image command), any help?

Answers (2)

Use subplot if you want separate plots in an array
for k = 1 : 20
subplot(4, 5, k);
imshow(..............
end

9 Comments

Thanks but I donot want the subplot, rather the plots must be on the same figure like the plots overlapping/non-overlapping on each other, it is easily implememted using hold on command in plot but it doesnot work in the case of image command. I generate 5 plots using for loop using image command, problem is that I want the 5 plots to be in the same figure using the image command. Any solution to this is much helpful?
Post an example of what you want, because clearly I was not understanding what you've written so far.
subplot() is the easiest way to get 5 plots. Why can't you use subplot()?
take for simplicity, this link for example - https://www.google.com/url?sa=i&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwim4J-RyJrhAhVOSX0KHXviDpsQjRx6BAgBEAU&url=https%3A%2F%2Freference.wolfram.com%2Flanguage%2Fref%2FPlot.html&psig=AOvVaw0EU-nGtWBF6eOE_HX-cGG5&ust=1553509498830912, here suppose I have loop 3 times and each time it plots one curve using image command, but I want the final figure to contain all the three plots in the single figure(using image command). Hope this makes the question clear?
Call hold on after your first plot
plot(t, y1, 'b-', 'LineWidth', 2);
hold on;
plot(t, y2, 'y-', 'LineWidth', 2);
plot(t, y3, 'g-', 'LineWidth', 2);
ax = gca;
ax.XAxisLocation = 'origin'; % Place x asis in the middle.
I am emphasizing that I am not using "plot" command rather I am using the "image" command. Using plot command I can do the "hold on" command for the plots to be in the same figure, but it is not the case when I am using the "image" command ("hold on" doesnot work for image command). Will "hold on" work when you are using image command, if not what is the alternative?
I am in a asituation that I cannot use the plot command, rather I have the choice to only use "image" command to plot from arrays.
How are you creating the bitmapped RGB images, that you then go on to display with image() or imshow()?
Sorry, but that was just an example of how three different plots are there in single figure. I want to do the same witht the image command
image() is fine to draw additional images in an axes when "hold on" is in effect.
Remember, though, that by default if you do not pass image() x, y data, or XData YData parameters, then image() is going to assume [1, number of columns] and [1, number of rows] as the XData and YData -- each pixel being one data unit. If your second image is the same size or later than the original image, then it is going to cover the original up completely -- unless, that is, that the newer image happens to have AlphaData set so that it is transparent in places.
im = imread('cameraman.tif');
image(im);
colormap(gray)
hold on
image([64 128], [64 128], img);
hold off
and observe that there is a smaller image overlayed on top of the first image. (Smaller because x y coordinates specified told it where the corners were to draw the image at.)
Remember, images are opaque by default, so you cannot see anything underneath an image unless you tell MATLAB to make the image transparent.

This question is closed.

Asked:

on 23 Mar 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!