"truesize" command doesn't work when using "subplot" and "imagesc"
7 views (last 30 days)
Show older comments
Hi all,
I'm trying to plot figures with "subplot" and "imagesc" with the use of the command "truesize". At the beginning everything worked fine, I changed a few things (I wanted to include "h.Label.String" where h=colorbar and "set(colorbar,'ylim',[0 30])" ) but I had errors and then nothing works as before. I tried resetting the default parameters (reset(gca)) but nothing seems to give me back the results I had. Here's the Matlab code:
c=jet(60);
subplot(3,3,1);
imagesc(image1);colorbar('westoutside');colormap(c);truesize;axis off;
subplot(3,3,2);
imagesc(image2);colormap(c);truesize;axis off;
subplot(3,3,3);
imagesc(image3);colormap(c);truesize;axis off;
subplot(3,3,4);
imagesc(image4);colormap(c);truesize;axis off;
The use of the command "truesize" cancels the "subplot" effetc and the colorbar doesn't show correctly on the figures. Please if you have any ideas on how I can make things work correctly again or on how I can reset everything so that things can be the way they were I would be very grateful. Thanks.
J
3 Comments
Walter Roberson
on 4 Apr 2019
Not documented is the key word here. When I look at the code, it appears to me that it fetches the CurrentAxes of the figure and works on it; it would call a different internal routine, Resize2(), for this purpose. However, when I look at that routine and try to analyze what is going on, it appears to me that it might be adjusting each image relative to the whole screen, rather than trying to fit the image into the axes.
If you have an image that you are sure fits into the current axes, then set the axes xlim and ylim to the number of columns and number of rows of pixels of the image, and set the DataAspectRatio to [1 1 1].
After that, set the InnerPosition to new values that reflect a width which is the number of columns of pixels and a height that is the number of rows. You will need to make decisions as to where you want to move the base: you could add half of the difference between the old size and the new size to the base location if you want the picture centered.
Do you have a need for each of the images to have a separate axes such as for zoom and pan and datatip purposes? If not, then perhaps the whole thing could be dealt with by montage()
Answers (0)
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!