Home > Matlab > Matlab: Figures without borders and toolbars

Matlab: Figures without borders and toolbars

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:

>>iptsetpref('ImshowBorder','tight');

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
>>set(0,'DefaultFigureMenu','none');
%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:

>>set(0,'Default');

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

Categories: Matlab Tags: ,
  1. Ben Taylor
    August 1st, 2007 at 18:43 | #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. LDM
    October 19th, 2010 at 17:11 | #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. PAVV
    March 11th, 2011 at 13:38 | #3

    Thank you so much for the tip. This will be very helpfull.

  4. Baker
    March 29th, 2011 at 19:48 | #4

    Thanks a ton, I was looking all over for this information. This was real helpful.

  5. a
    April 20th, 2011 at 13:54 | #5

    that’s totally awesome, thanks!

  6. rory
    August 30th, 2011 at 21:13 | #6

    thank you!

  7. r
    January 4th, 2012 at 23:39 | #7

    not working for imagesc command.

  1. No trackbacks yet.