Remove spacing in matlab subplot

后端 未结 3 668
谎友^
谎友^ 2020-12-16 01:06

How should i remove the empty space between these images?i need to combine all these images without any space.


bot=imread(\'bot.jpeg         


        
相关标签:
3条回答
  • 2020-12-16 01:27

    I copy the answer from mathworks:

    For each subplot, store its handle.

     h = subplot(2,3,1);
    

    Then set the 'position' property of h to be anything you want.

     p = get(h, 'pos');
    

    This is a 4-element vector [left, bottom, width, height] which by default is in normalized coordinates (percentage of figure window). For instance, to add 0.05 units (5% of figure window) to the width, do this:

     p(3) = p(3) + 0.05;
     set(h, 'pos', p);
    

    The SUBPLOT command picks standard values for these parameters, but they could be anything you want. You could put axes anywhere on the figure you want, any size you want.

    You can check for it: http://www.mathworks.com/matlabcentral/newsreader/view_thread/144116

    0 讨论(0)
  • 2020-12-16 01:30

    You need to specify axes' 'Position' property when you create them with subplot.

    Also, you have to adjust figure aspect ratio to match that of the image, so that all figures fit without vertical or horizontal space.

    If you show a different image in each subplot, all images should have the same aspect ratio, otherwise it's not possible for them to fit in the figure without empty spaces.

    bot = imread('peppers.png');
    for i= 1:25
        subplot('Position',[(mod(i-1,5))/5 1-(ceil(i/5))/5 1/5 1/5])
        imshow(bot); %// or show a different image on each subplot
    end
    p = get(gcf,'Position');
    k = [size(bot,2) size(bot,1)]/(size(bot,2)+size(bot,1));
    set(gcf,'Position',[p(1) p(2) (p(3)+p(4)).*k]) %// adjust figure x and y size
    

    enter image description here

    0 讨论(0)
  • 2020-12-16 01:51

    The most canonical way would be to take a look at this answer by bla here. This answer uses a function from the MATLAB File Exchange in order to achieve the answer. However, that requires learning a new function and playing around with the parameters.

    If you want something working immediately, instead of showing each subimage in a separate grid on a plot, I would simply create a new image that stacks all of those images together:

    bot_new = repmat(bot, [5 5]);
    imshow(bot_new);
    

    repmat takes a matrix and duplicates / stacks / tiles itself together for as many rows and as many columns (or in any dimension) that you want. In this case, I chose to stack the image so that there are 5 rows and 5 columns of it. We next show the stacked image together with imshow.

    If we used an example image from MATLAB:

    bot = imread('onion.png');
    

    If we ran the above code that tiles the images together and showed the image, this is what we get:

    enter image description here

    0 讨论(0)
提交回复
热议问题