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.

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)

By : Kena


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:


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.

By : gnovice

You can use the set command.


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

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');

This video can help you solving your question :)
By: admin