Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Filled 2-D polygons

`fill(X,Y,C)`

fill(X,Y,* ColorSpec*)

fill(X1,Y1,C1,X2,Y2,C2,...)

fill(...,'

`PropertyName`

fill(ax,...)

h = fill(...)

The `fill`

function creates colored polygons.

`fill(X,Y,C)`

creates filled
polygons from the data in `X`

and `Y`

with
vertex color specified by `C`

. `C`

is
a vector or matrix used as an index into the colormap. If `C`

is
a row vector, `length(C)`

must equal `size(X,2)`

and `size(Y,2)`

;
if `C`

is a column vector, `length(C)`

must
equal `size(X,1)`

and `size(Y,1)`

.
If necessary, `fill`

closes the polygon by connecting
the last vertex to the first. The values in `X`

and `Y`

can
be numeric, datetime, duration, or categorical values.

`fill(X,Y,`

fills two-dimensional polygons specified by * ColorSpec*)

`X`

and `Y`

with
the color specified by `ColorSpec`

. `fill(X1,Y1,C1,X2,Y2,C2,...)`

specifies
multiple two-dimensional filled areas.

`fill(...,'`

allows
you to specify property names and values for a patch graphics object.* PropertyName*',PropertyValue)

`fill(ax,...)`

creates the polygons in the
axes specified by `ax`

instead of in the current
axes (`gca`

). The option `ax`

can
precede any of the input argument combinations in the previous syntaxes.

`h = fill(...)`

returns a
vector of patch objects.

If `X`

or `Y`

is a matrix,
and the other is a column vector with the same number of elements
as rows in the matrix, `fill`

replicates the column
vector argument to produce a matrix of the required size. `fill`

forms
a vertex from corresponding elements in `X`

and `Y`

and
creates one polygon from the data in each column.

If `X`

or `Y`

contains one
or more `NaN`

values, then `fill`

does
not fill the polygons.

The type of color shading depends on how you specify color in
the argument list. If you specify color using `ColorSpec`

, `fill`

generates
flat-shaded polygons by setting the patch object's `FaceColor`

property
to the corresponding RGB triplet.

If you specify color using `C`

, `fill`

scales
the elements of `C`

by the values specified by the
axes property `CLim`

. After scaling `C`

, `C`

indexes
the current colormap.

If `C`

is a row vector, `fill`

generates
flat-shaded polygons where each element determines the color of the
polygon defined by the respective column of the `X`

and `Y`

matrices.
Each patch object’s `FaceColor`

property is
set to `'flat'`

. Each row element becomes the `CData`

property
value for the `n`

th patch object, where *n* is
the corresponding column in `X`

or `Y`

.

If `C`

is a column vector or a matrix, `fill`

uses
a linear interpolation of the vertex colors to generate polygons with
interpolated colors. It sets the patch graphics object `FaceColor`

property
to `'interp'`

and the elements in one column become
the `CData`

property value for the respective patch
object. If `C`

is a column vector, `fill`

replicates
the column vector to produce the required sized matrix.