Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 591
Radrider33 Avatar asked Apr 24 '12 04:04

Radrider33


2 Answers

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.

like image 137
H.Muster Avatar answered Nov 12 '22 11:11

H.Muster


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.

like image 22
Egon Avatar answered Nov 12 '22 09:11

Egon