How to set subtitle size in MATLAB figure?

I often have to compose 10 images together, but using this code small images are provided:

img = rand(400,600); for i=1:10 subplot(2,5,i); imshow(img); title(['Image ' int2str(i)]); end 

As you can see, the images do not use all the available space on the screen. How to increase the size or reduce the indents / borders between them?

enter image description here

Thanks for any help.

+8
screen matlab plot fullscreen figure
source share
4 answers

I do not believe that there is an easy way to do this. There are two options:

First use the position of the subtitle position:

 >> subplot(2,5, i, [l, b, w, h]) 

and calculate the left, bottom, width, height.

Or, take the handle of the returned axis:

 >> h(i) = subplot(2,5,i); 

and then change the axis after.

 >> set(h(1), 'position', [l, b, w, h] ); 

There are several pages that will contain more detailed information, for example http://www.briandalessandro.com/blog/how-to-make-a-borderless-subplot-of-images-in-matlab/

[update]

The code below contains a bit more information about who you can do something like what you are looking for. This is a little tiring. 0.95 and 0.02 are just a small addition. They are not magical. :-)

Another thing to note is that I recommend that you use β€œii” as the index variable (or something else), since β€œi” is defined as sqrt (-1). A good convention is not to use "i" and "j" as index variables (especially in Matlab).

 img = rand(400,600); figure(1); clf(); hold on; % Get the width and height of the figure lbwh = get(1, 'position'); figw = lbwh(3); figh = lbwh(4); % Number of rows and columns of axes ncols = 5; nrows = 2; % w and h of each axis in normalized units axisw = (1 / ncols) * 0.95 axish = (1 / nrows) * 0.95 for ii=1:10 % calculate the row and column of the subplot row = floor( ii/(ncols+1) ) + 1 col = mod( ii-1, ncols ) + 1 % calculate the left, bottom coordinate of this subplot axisl = (axisw+0.02) * (col-1) axisb = (axish+0.02) * (row-1) % plot the subplot h= subplot('position', [axisl, axisb, axisw, axish] ); imshow(img); title(['Image ' int2str(ii)]); pause end 

You will need to play with him to do exactly what you want. And "help" is your friend.

+7
source share

I often have this requirement, and the most efficient way for me is to use the third subplot_tight function, or less to replace subplot . In the simplest case, you can do

 figure(1); clf subplot_tight(1,2,1, [0.05 0.05]) %normal plot stuff 

where two parameters in the fourth argument control part of the visible space around the image.

+4
source share

Based on @brechmos answer, when your subtitle number is more than 10 subtitles, then its code will cause an error.

  % calculate the row and column of the subplot row = floor( ii/(ncols+1) ) + 1 col = mod( ii-1, ncols ) + 1 

eg. 4X5, then subrecord 11 will be incorrectly interpreted as (2, 1), but not (3.1).

Replace it with the following code:

 % calculate current row and column of the subplot row = floor( (i-0.5)/ncols ) + 1; col = mod(i-(row-1)*ncols, ncols+1); 
+3
source share

You can use the shape properties parameter as soon as you create the plot. Click on the subtitle you want to change. From the property editor, select the "more properties" option. There, if you scroll down the page, you will see the "Position" tab. You can change these values ​​to see how the subtitle moves, and thus customize the subtitle to your preference.

0
source share

All Articles