Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MATLAB, how do I change the background color of a subplot?

I'm trying to change the background color of a single subplot in a MATLAB figure.

It's clearly feasible since the UI allows it, but I cannot find the function to automate it.

I've looked into whitebg, but it changes the color scheme of the whole figure, not just the current subplot.

(I'm using MATLAB Version 6.1 by the way)

like image 216
Kena Avatar asked Oct 01 '08 13:10

Kena


3 Answers

You can use the set command.

set(subplot(2,2,1),'Color','Red')

That will give you a red background in the subplot location 2,2,1.

like image 143
Doug Trojan Avatar answered Oct 23 '22 01:10

Doug Trojan


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:

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.

like image 39
gnovice Avatar answered Oct 23 '22 01:10

gnovice


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.

subplot(3, 2, 4), hist(rand(50)), whitebg('y');
like image 2
Douglas F Shearer Avatar answered Oct 23 '22 02:10

Douglas F Shearer