light

Creates a light source in the current axes.

Category: Graphics > Formatting and Annotation

Syntax

light

Adds a white, infinitely distant light at the default position [1 0 1].

light(Name, Value)

Sets properties such as 'Position', 'Color' and 'Style'.

h = light(___)

Also returns the light object.

Description

A light only has a visible effect on surfaces and patches whose lighting mode is not 'none'. Set it with lighting gouraud or lighting flat. Without a light object, such surfaces are not shaded.

Several lights can be added to one axes. To place a light by angles instead of coordinates, use lightangle or camlight.

Input arguments

Position
Three-element vector [x y z]. For the 'infinite' style it is the direction of the light; for 'local' it is a point in space.
Color
RGB triplet or color name. Default white.
Style
'infinite' (default) or 'local'.

Output arguments

h
Light object, class matlab.graphics.primitive.Light.

Example

A lit surface

surf(peaks(30))
shading interp
lighting gouraud
h = light('Position', [-1 -1 1]);
h.Style
h.Position
Output
ans = 'infinite'
ans = 1×3

    -1    -1     1

See also

lightangle camlight lighting material shading