Something that has bothered me for *the entire* time I’ve used it is that when you show images using ‘imshow’ the resulting figure has the image surrounded in a sea of gray border. Well, I hate that gray border. It serves no purpose and today I have figured out how to remove it!

Matlab runs a script called ‘startup.m’ when it starts. This is located in your ~/matlab/ directory. If you include this line into that file (or just type it before you make the figure) then you remove the gray border:


Its glorious… Now the picture scales to fill the whole window! (note this only works with the ‘imshow’ command, not ‘imagesc’).

BUT! That’s not all. I also learned about some other cute little tricks that should be included in your startup.m (if you’re me at least).

%removes menu and toolbar from all new figures
%makes disp() calls show things without empty lines
>>format compact;

I feel like these three commands cut a lot of the pointless (inefficient) crap out of Matlab’s default display interface. Thanks to commenter Matt who pointed me toward the set(0,’Default… thing. You can use this to set up *tons* of settings so that you don’t have to set it every time. Just call:


For some other useful tips on exporting figures for papers, check this related post.

15 thoughts on “Matlab: Figures without borders and toolbars

  1. Thanks, mathworks is not very helpful with removing this. I searched everywhere for “margin”, figure border, etc… I agree that it serves no purpose and it ugly. I will include this line in all of my new matlab function along with “format compact”;

  2. Wonderful. So simple, yet, impossible to figure out without your hint. This should be a default when saving/printing images to files. Thanks a ton.

  3. Thanks,
    Really useful :).
    It can remove the annoying white spaces around the figures in MATLAB when I convert the figure to EPS, TIFF, PNG, JPEG or any other format.

  4. Hi , I wonder why the left and right borders are still not removed in the saved figured … can you help me in this ??

    Thanks !

Leave a Reply

Your email address will not be published.