Question

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)

Was it helpful?

Solution

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.

OTHER TIPS

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.

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');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top