在 MATLAB 中,如何更改子图的背景颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/157685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In MATLAB, how do I change the background color of a subplot?
提问by Kena
I'm trying to change the background color of a single subplot in a MATLAB figure.
我正在尝试更改 MATLAB 图中单个子图的背景颜色。
It's clearly feasible since the UI allows it, but I cannot find the function to automate it.
这显然是可行的,因为 UI 允许它,但我找不到自动化的功能。
I've looked into whitebg, but it changes the color scheme of the whole figure, not just the current subplot.
我已经研究过whitebg,但它改变了整个图形的配色方案,而不仅仅是当前的子图。
(I'm using MATLAB Version 6.1 by the way)
(顺便说一下,我使用的是 MATLAB 6.1 版)
回答by Doug Trojan
You can use the set command.
您可以使用 set 命令。
set(subplot(2,2,1),'Color','Red')
That will give you a red background in the subplot location 2,2,1.
这将在子图位置 2,2,1 中为您提供红色背景。
回答by gnovice
I know you mentioned that you are using MATLAB 6.1, but it bears mentioning that in the newer versions of MATLAB you can specify additional property-value pair arguments in the initial call to SUBPLOT, allowing for a more compact syntax. The following creates an axes with a red background in the top left corner of a 2-by-2 layout:
我知道您提到您使用的是 MATLAB 6.1,但值得一提的是,在较新版本的 MATLAB 中,您可以在对SUBPLOT的初始调用中指定额外的属性-值对参数,从而实现更紧凑的语法。下面在 2×2 布局的左上角创建一个带有红色背景的轴:
subplot(2,2,1,'Color','r');
I'm not certain in which version of MATLAB this syntax was introduced, since the release notes going back to Version 7 (R14)don't seem to mention it.
我不确定这个语法是在哪个版本的 MATLAB 中引入的,因为回到版本 7 (R14)的发行说明似乎没有提到它。
回答by Douglas F Shearer
I've not used Matlab in several years, but I think it might well be the whitebg method called after the subplot declaration, similar to the way in which you would set a title.
我已经好几年没有使用 Matlab 了,但我认为它很可能是在 subplot 声明之后调用的 whitebg 方法,类似于您设置标题的方式。
subplot(3, 2, 4), hist(rand(50)), whitebg('y');

