xregion

Shades a vertical band between two x values.

Category: Graphics > Formatting and Annotation

Syntax

xregion(x1, x2)

Shades the band from x1 to x2 over the full height of the axes.

xregion(x1, x2, Name, Value)

Sets properties such as 'FaceColor' and 'FaceAlpha'.

xr = xregion(___)

Returns the region object.

Description

The band stays attached to its x values, so it fills the whole plot height whatever the limits. It does not change the automatic limits. It is used to show a time window, an acceptable range or a part of the data that gets special treatment.

The horizontal counterpart is yregion.

Input arguments

x1, x2
Edges of the band along the x-axis. Vectors of equal length draw several bands.

Output arguments

xr
Constant region object, class matlab.graphics.chart.decoration.ConstantRegion, with the property Value holding [x1 x2].

Example

Highlight a window

t = 0:0.1:10;
plot(t, sin(t))
r = xregion(3, 5, 'FaceColor', 'g');
r.Value
Output
ans = 1×2

     3     5

See also

yregion xline patch xlim rectangle