Matlab:不包含边界和工具栏的figure(移除保存图片的白边)

来源:互联网 发布:人工智能豆瓣 编辑:程序博客网 时间:2024/05/22 10:59

当我们使用matlab的imshow命令显示图片时,会有白框和工具栏出现。在保存图片时会出现白色的边框。下面将说明如何去除这些显示。


Matlab启动时运行脚本'script.m',文件位置在~/matlab/ directory(windows下在matlab安装路径的bin目录下新建script.m译者注)。在该文件加上一行,或者在显示figure时加命令

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

图片即可显示,并且保存时没有白框。此方法仅仅适用'imshow'命令,不适用'imagesc'命令。


如果在'startup.m'文件中包含以下命令:

%在所有的figure去除菜单栏和工具栏
>>set(0,'DefaultFigureMenu','none');
%'disp'命令显示无空行
>>format compact;

这三条命令可以去除matlab默认的很多没有意义的显示信息。


翻译原文:http://www.shawnlankton.com/2007/06/matlab-figures-without-borders-and-toolbars/comment-page-1/#comment-2101

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.

0 0
原创粉丝点击