plot - How can I set subplot size in MATLAB figure? -
i need plot 10 images together, using code results in small images :
img = rand(400,600); i=1:10 subplot(2,5,i); imshow(img); title(['image ' int2str(i)]); end
as can see, images not use available space in screen. how can increase size, or decrease padding/margin between them?
thanks help.
i don't believe there easy way it. there 2 options:
first, use position part of subplot:
>> subplot(2,5, i, [l, b, w, h])
and calculate left, bottom, width, height.
or, handle of returned axis:
>> h(i) = subplot(2,5,i);
and modify axis afterward.
>> set(h(1), 'position', [l, b, w, h] );
there number of pages give more detail, e.g., http://www.briandalessandro.com/blog/how-to-make-a-borderless-subplot-of-images-in-matlab/
[update]
the code below gives little more detail on can looking for. tad tedious. 0.95 , 0.02 give little padding. nothing magical. :-)
one other thing note encourage use "ii" index variable (or else) "i" defined sqrt(-1). convention not use "i" , "j" index variables (especially in matlab).
img = rand(400,600); figure(1); clf(); hold on; % width , height of figure lbwh = get(1, 'position'); figw = lbwh(3); figh = lbwh(4); % number of rows , columns of axes ncols = 5; nrows = 2; % w , h of each axis in normalized units axisw = (1 / ncols) * 0.95 axish = (1 / nrows) * 0.95 ii=1:10 % calculate row , column of subplot row = floor( ii/(ncols+1) ) + 1 col = mod( ii-1, ncols ) + 1 % calculate left, bottom coordinate of subplot axisl = (axisw+0.02) * (col-1) axisb = (axish+0.02) * (row-1) % plot subplot h= subplot('position', [axisl, axisb, axisw, axish] ); imshow(img); title(['image ' int2str(ii)]); pause end
you have play make want. , "help" friend.
Comments
Post a Comment