在MATLAB中,如何更改子图的背景颜色?

时间:2022-12-26 23:42:07

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 Version 6.1)

3 个解决方案

#1


20  

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给你一个红色背景。

#2


4  

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)似乎没有提到它。

#3


2  

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,但我认为它可能是在子图声明之后调用的whitebg方法,类似于设置标题的方式。

subplot(3, 2, 4), hist(rand(50)), whitebg('y');

#1


20  

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给你一个红色背景。

#2


4  

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)似乎没有提到它。

#3


2  

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,但我认为它可能是在子图声明之后调用的whitebg方法,类似于设置标题的方式。

subplot(3, 2, 4), hist(rand(50)), whitebg('y');