Setting the background color of a plot in MATLAB using the command line?

42,968

Solution 1

The solution to your specifiec question, is given by @M.Huster. I will just show you how you can help yourself in these cases.

Just make your plot and apply any manual changes you'd like. Then, in the figure window choose the option "Generate Code" in the File menu. This will generate an m-file that takes a dataset and recreates the figure for that dataset. If you look at that code (which is generally quite readable), you will see what commands are responsible for a certain effect.

As @M.Huster said, you can use get to get the properties, a more graphic way is using inspect(gca) and even better is the uiinspect command written by Yair Altman.

Solution 2

To change the background color of the axis:

 set(gca, 'color', [1 1 0])

To change the background color of the figure:

 set(gcf, 'color', [1 1 0])

In general, if you want to know the properties of a plot, try

get(gca) % for axis properties  
get(gcf) % for figure properties

This will return a list of available property names and property values.

Share:
42,968
Radrider33
Author by

Radrider33

iOS developer, Electrical Engineering Undergrad at University of Colorado Boulder

Updated on July 05, 2022

Comments

  • Radrider33
    Radrider33 almost 2 years

    I am doing an assignment for my programming class, and I need to create a plot, along with a line of best fit for a few data points using only the command line in MATLAB. I know how to set the background using the figure editor, but I cannot for the life of me figure out how to do it via the command line. I need to set it to yellow. How would I do this? I think I am just missing something simple.

  • Radrider33
    Radrider33 about 12 years
    Thanks for the helpful answer!