Main Content

Default Property Values

Predefined Values for Properties

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

Specify Default Values

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:


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:


The character vector defaultLineLineWidth identifies the property as a line property. To specify the figure color, use defaultFigureColor.


Where in Hierarchy to Define Default

In general, you should define a default value on the root level so that all subsequent plotting functions 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.


List Default Values

Use get to determine what default values are currently set on any given object level:


returns all default values set in your current MATLAB session.

Set Properties to the Current Default

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:

h = surface(peaks);

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.

Remove Default Values

Specifying a property value of 'remove' gets rid of user-defined default values. The statement


removes the definition of the default surface EdgeColor from the root.

Set Properties to Factory-Defined Values

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:

h = surface(peaks);

List Factory-Defined Property Values

You can list factory values:

  • get(groot,'factory') — List all factory-defined property values for all graphics objects

  • get(groot,'factoryObjectType') — List all factory-defined property values for a specific object

  • get(groot,'factoryObjectTypePropertyName') — List factory-defined value for the specified property.

Reserved Words

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