Documentation Center

  • Trial Software
  • Product Updates

Light Properties

Light properties

Creating Light Objects

Use light to create light objects.

Modifying Properties

You can set and query graphics object properties in two ways:

  • Customize Objects in Graph is an interactive tool that enables you to see and change object property values.

  • The set and get commands enable you to set and query the values of properties.

To change the default values of properties, see Setting Default Property Values.

See Core Graphics Objects for general information about this type of object.

Light Property Descriptions

This section provides a description of properties. Curly braces { } enclose default values.

BeingDeleted

on | {off} (read-only)

This object is being deleted. Mechanism to determine if objects are in the process of being deleted. MATLAB® sets the BeingDeleted property to on when the object's delete function callback is called (see the DeleteFcn property). It remains set to on while the delete function executes, after which the object no longer exists.

For example, an object's delete function calls other functions that act on a number of different objects. If a function does not need to perform an action on an about-be-deleted object, it can check the object's BeingDeleted property before acting.

BusyAction

cancel | {queue}

Callback queuing

Determines how MATLAB handles the execution of interrupting callbacks.

A running callback is the currently executing callback. The interrupting callback is the callback that tries to interrupt the running callback. The BusyAction property of the interrupting callback determines how MATLAB handles its execution. When the BusyAction property is set to:

  • 'queue' — Puts the interrupting callback in a queue to be processed after the running callback finishes execution.

  • 'cancel' — Discards the interrupting callback as MATLAB finishes execution.

For information about how the Interruptible property of the callback controls whether other callbacks can interrupt the running callback, see the Interruptible property description.

ButtonDownFcn

function handle

This property is not used on lights.

Children

handles

The empty matrix; light objects have no children.

Clipping

on | off

Clipping mode. This property has no effect on light objects.

Color

ColorSpec

Light color. Defines the color of the light emanating from the light object. Use a three-element RGB vector or one of the MATLAB predefined names. Default value is [1 1 1] (white). See the ColorSpec reference page for more information on specifying color.

CreateFcn

function handle | cell array containing function handle and additional arguments | string (not recommended)

Callback function executed during object creation. Executes when MATLAB creates a light object. You must define this property as a default value for lights or in a call to the light function to create a new light object. For example, the following statement:

set(0,'DefaultLightCreateFcn',@light_create)

defines a default value for the line CreateFcn property on the root level that sets the current figure colormap to gray and uses a reddish light color whenever you create a light object.

function light_create(src,evnt)
% src - the object that is the source of the event 
% evnt - empty for this property
	set(src,'Color',[.9 .2 .2])
	set(gcbf,'Colormap',gray)
end

MATLAB executes this function after setting all light properties. Setting this property on an existing light object has no effect. The function must define at least two input arguments (handle of light object created and an event structure, which is empty for this property).

The handle of the object whose CreateFcn is being executed is passed by MATLAB as the first argument to the callback function and is also accessible through the root CallbackObject property, which you can query using gcbo.

For information on the syntax of callback functions, see Function Handle Callbacks.

DeleteFcn

function handle | cell array containing function handle and additional arguments | string (not recommended)

Delete light callback function. Executes when you delete the light object (for example, when you issue a delete command or clear the axes cla or figure clf).

For example, the following function displays object property data before the object is deleted.

function delete_fcn(src,evnt)
% src - the object that is the source of the event 
% evnt - empty for this property
   obj_tp = get(src,'Type');
   disp([obj_tp, ' object deleted'])
   disp('Its user data is:')
   disp(get(src,'UserData'))
end

MATLAB executes the function before deleting the object's properties so these values are available to the callback function. The function must define at least two input arguments (handle of object being deleted and an event structure, which is empty for this property).

The handle of the object whose DeleteFcn is being executed is passed by MATLAB as the first argument to the callback function and is also accessible through the root CallbackObject property, which you can query using gcbo.

For information on the syntax of callback functions, see Function Handle Callbacks.

HandleVisibility

{on} | callback | off

Control access to object's handle. Determines when an object's handle is visible in its parent's list of children. HandleVisibility is useful for preventing command-line users from accidentally drawing into or deleting a figure that contains only user interface devices (such as a dialog box).

  • on — Handles are always visible.

  • callback — Handles are visible from within callback routines or functions invoked by callback routines, but not from within functions invoked from the command line. This provides a means to protect GUIs from command-line users, while allowing callback routines to have access to object handles.

  • off — Handles are invisible at all times. Use this option when a callback invokes a function that could damage the GUI (such as evaluating a user-typed string). This option temporarily hides its own handles during the execution of that function.

When a handle is not visible in its parent's list of children, it cannot be returned by functions that obtain handles by searching the object hierarchy or querying handle properties. This includes get, findobj, gca, gcf, gco, newplot, cla, clf, and close.

When a handle's visibility is restricted using callback or off, the object's handle does not appear in its parent's Children property, figures do not appear in the root's CurrentFigure property, objects do not appear in the root's CallbackObject property or in the figure's CurrentObject property, and axes do not appear in their parent's CurrentAxes property.

You can set the root ShowHiddenHandles property to on to make all handles visible regardless of their HandleVisibility settings (this does not affect the values of the HandleVisibility properties).

Handles that are hidden are still valid. If you know an object's handle, you can set and get its properties, and pass it to any function that operates on handles.

HitTest

{on} | off

This property is not used by light objects.

Interruptible

off | {on}

Callback routine interruption

Controls whether MATLAB can interrupt an object's callback function when subsequent callbacks attempt to interrupt it.

For Graphics objects, the Interruptible property affects only the callbacks for theButtonDownFcn property. A running callback is the currently executing callback. The interrupting callback is the callback that tries to interrupt the running callback. MATLAB handles both the callbacks based on the Interruptible property of the object of the running callback.

When the Interruptible property is set to:

  • 'off', MATLAB finishes execution of the running callback without any interruptions

  • 'on', these conditions apply:

    • If there is a drawnow, figure, getframe, waitfor, or pause command in the running callback, then MATLAB executes the interrupting callbacks which are already in the queue and returns to finish execution of the current callback.

    • If one of the above functions is not in the running callback, then MATLAB finishes execution of the current callback without any interruption.

BusyAction property of the object of interrupting callback determines whether the callback should be ignored or should be put in the queue.

Setting Interruptible property to on (default), allows a callback from other graphics objects to interrupt callback functions originating from this object.

    Note:   MATLAB does not save the state of properties or the display when an interruption occurs. For example, the handle returned by the gca or gcf command may be changed as another callback is executed.

After the function that interrupts a callback completes, the callback resumes execution where it halted when interrupted. For more information, see Control Callback Execution and Interruption.

Parent

handle of parent axes

Parent of light object. This property contains the handle of the light object's parent. The parent of a light object is the axes object that contains it.

Note that light objects cannot be parented to hggroup or hgtransform objects.

Position

[x,y,z] in axes data units

Location of light object. Vector defining the location of the light object. The vector is defined from the origin to the specified x-, y-, and z-coordinates. The placement of the light depends on the setting of the Style property:

  • If the Style property is local, Position specifies the actual location of the light (which is then a point source that radiates from the location in all directions).

  • If the Style property is infinite, Position specifies the direction from which the light shines in parallel rays.

Selected

on | off

This property is not used by light objects.

SelectionHighlight

{on} | off

This property is not used by light objects.

Style

{infinite} | local

Parallel or divergent light source.

  • infinite — MATLAB places the light object at infinity (light rays are parallel).

  • local — MATLAB places the light object at the location specified by the Position property (light rays diverge in all directions).

Tag

string

User-specified object label. Provides a means to identify graphics objects with a user-specified label. The default is an empty string.

Use the Tag property and the findobj function to manipulate specific objects within a plotting hierarchy.

Type

string (read-only)

Type of graphics object. String that identifies the class of the graphics object. Use this property to find all objects of a given type within a plotting hierarchy. For light objects, Type is always 'light'.

UIContextMenu

handle of uicontextmenu object

This property is not used by light objects.

UserData

matrix

User-specified data. Data you want to associate with the light object. The default value is an empty array. MATLAB does not use this data, but you can access it using the set and get commands.

Visible

{on} | off

Light visibility. While light objects themselves are not visible, you can see the light on patch and surface objects. When you set Visible to off, the light emanating from the source is not visible. There must be at least one light object in the axes whose Visible property is on for any lighting features to be enabled (including the axes AmbientLightColor and patch and surface AmbientStrength ).

See Also

Was this topic helpful?