SamuelNLP
SamuelNLP

Reputation: 4136

How to make the plot area maximized inside figure of MATLAB

How can I essentially make the white plot area occupy all the figure, not wasting the figure space with the grey area.

I could not find any propriety for it in the doc of figure,

Example of figure,

enter image description here

I want the 5 plot to be connected without any grey space outside them.

UPDATE:

set(gca,'Position',get(gca,'OuterPosition'));

this code make them stretch horizontally but not vertically.

enter image description here

Upvotes: 1

Views: 2379

Answers (1)

Jens Boldsen
Jens Boldsen

Reputation: 1275

First:

set(gca,'Units','normalized','Position',[0,0,1,1]);

If that doesn't help enough try:

axis normal;

EDIT: Here's a solution that works for subplots: Use the following function instead of the usual subplot function:

function varargout = tightSubplot(m,n,i)
    [x,y] = ind2sub([m,n],i);
    if nargout > 0
        varargout{1} = axes('units','normalized','position',[(x-1)/m,(y-1)/n,1/m,1/n]);
    else
        axes('units','normalized','position',[(x-1)/m,(y-1)/n,1/m,1/n]);
    end
end

Upvotes: 1

Related Questions