Nearly all graphics object properties have predefined values. Predefined values originate from two possible sources:
Default values defined on an ancestor of the object
Factory values defined on the root of the graphics object hierarchy
Users can create default values for an object property, which take precedence over the factory-defined values. Objects use default values when:
Created in a hierarchy where an ancestor defines a default value
Parented into a hierarchy where an ancestor defines a default value
Define a default property value using a character vector with these three parts:
'default' ObjectType PropertyName
The word default
The object type (for example, Line
)
The property name (for example, LineWidth
)
A character vector that specified the default line LineWidth
would
be:
'defaultLineLineWidth'
Use this character vector to specify the default value. For
example, to specify a default value of 2 points for the line LineWidth
property,
use the statement:
set(groot,'defaultLineLineWidth',2)
The character vector defaultLineLineWidth
identifies
the property as a line property. To specify the figure color, use defaultFigureColor
.
set(groot,'defaultFigureColor','b')
In general, you should define a default value on the root level
so that all subsequent plotting function use those defaults. Specify
the root in set
and get
statements
using the groot
function, which
returns the handle to the root.
You can define default property values on three levels:
Root — values apply to objects created in current MATLAB® session
Figure — use for default values applied to children of the figure defining the defaults.
Axes — use for default values applied only
to children of the axes defining the defaults and only when using
low-level functions (light
, line
, ,patch
, rectangle
, surface
, text
, and the low-level form of image
).
For example, specify a default figure color only on the root level.
set(groot,'defaultFigureColor','b')
Use get
to determine
what default values are currently set on any given object level:
get(groot,'default')
returns all default values set in your current MATLAB session.
Specifying a property value of 'default'
sets
the property to the first encountered default value defined for that
property. For example, these statements result in a green surface EdgeColor
:
set(groot,'defaultSurfaceEdgeColor','k') h = surface(peaks); set(gcf,'defaultSurfaceEdgeColor','g') set(h,'EdgeColor','default')
Because a default value for surface EdgeColor
exists
on the figure level, MATLAB encounters this value first and uses
it instead of the default EdgeColor
defined on
the root.
Specifying a property value of 'remove'
gets
rid of user-defined default values. The statement
set(groot,'defaultSurfaceEdgeColor','remove')
removes the definition of the default surface EdgeColor
from
the root.
Specifying a property value of 'factory'
sets
the property to its factory-defined value. For example, these statements
set the EdgeColor
of surface h
to
black (its factory setting), regardless of what default values you
have defined:
set(gcf,'defaultSurfaceEdgeColor','g') h = surface(peaks); set(h,'EdgeColor','factory')
You can list factory values:
get(groot,'factory')
— List
all factory-defined property values for all graphics objects
get(groot,'factory
—
List all factory-defined property values for a specific objectObjectType
')
get(groot,'factory
—
List factory-defined value for the specified property.ObjectTypePropertyName
')
Setting a property value to default
, remove
,
or factory
produces the effects described in the
previous sections. To set a property to one of these words (for example,
a text String
property set to the word default
),
precede the word with the backslash character:
h = text('String','\default');