Matlab Cropping Plots

1.1k Views Asked by At

I want to adjust the amount of whitespace that is shown when plots are generated. I found this command to do just that:

set(gca,'LooseInset',get(gca,'TightInset'))

But this doesn't work that well when I add axis labels. When I have a plot without axis labels it's fine, it looks like this: enter image description here

But when I add labels it does this: enter image description here

You can't see it all that well but there is a lot of white space left of the yaxis label. I want to crop it down to the bare minimum, how do I do it?

1

There are 1 best solutions below

5
On BEST ANSWER

Try this:

set( gca, 'Position', get( gca, 'OuterPosition' ) - ...
  get( gca, 'TightInset' ) * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1] );

Here is an example of what the above does:

figure
plot( 1:10 )
ylabel( 'Y Axis' );
xlabel( 'X Axis' );

Before:

enter image description here

After:

enter image description here

And side-by-side before the printing:

enter image description here