How to control the margin size around subplots?

Since MATLAB R2019b you can use tiledlayout function to control the spacing of the subplots.


Here's an example which shows how to obtain subplots without tile spacing:

figure
example_image = imread('cameraman.tif');
t = tiledlayout(5,3);
nexttile

for c= 1:15
    imagesc(example_image(:,c))
    if c < 15
        nexttile
    end
end

t.TileSpacing = 'None';

The problem is that Matlab assigns the position property of each axis such that there is space around each plot. You can either adjust the position property, or you can get subaxis from the File Exchange and set up the subplots the way you like.


Take a look at the axes's LooseInset and OuterPosition properties: http://undocumentedmatlab.com/blog/axes-looseinset-property/