This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Filled area 2-D plot


ar = area(...)


An area graph displays elements in Y as one or more curves and fills the area beneath each curve. When Y is a matrix, the curves are stacked showing the relative contribution of each row element to the total height of the curve at each x interval.

area(Y) plots the vector Y or plots each column in matrix Y as a separate curve and stacks the curves. The x-axis automatically scales to 1:size(Y,1). The values in Y can be numeric or duration values.

area(X,Y) plots Y versus X and fills the area between 0 and Y. The values in X can be numeric, datetime, duration or categorical values.

  • If Y is a vector, then specify X as a vector of increasing values with length equal to Y. If the values in X are not increasing, then area sorts the values before plotting.

  • If Y is a matrix, then specify X as a vector of increasing values with length equal to the number of rows in Y. area plots the columns of Y as filled areas. For each X, the net result is the sum of corresponding values from the rows of Y. You also can specify X as a matrix with size equal to Y. To avoid unexpected output when X is a matrix, specify X so that the columns repeat.

area(...,basevalue) specifies the base value for the area fill. The default basevalue is 0. Specify the base value as a numeric value.

area(...,Name,Value) modifies the area chart using one or more name-value pair arguments.

area(ax,...) plots into the axes ax instead of into the current axes (gca).

ar = area(...) returns one or more Area objects. The area function creates one Area object for vector input arguments. It creates one object per column for matrix input arguments.

Creating an area graph of an m-by-n matrix creates n area objects (that is, one per column), whereas a 1-by-n vector creates one area object.

Some area object properties that you set on an individual area object set the values for all area objects in the graph. See Area Properties for information on specific properties.


collapse all

Plot the data in matrix Y as an area graph.

Y = [1, 5, 3;
     3, 2, 7;
     1, 5, 3;
     2, 6, 1];

By default, area uses the y-axis as the base value. Change the base value by setting the basevalue input argument to -4.

Y = [1, 5, 3;
     3, 2, 7;
     1, 5, 3;
     2, 6, 1];
basevalue = -4;

Create an area plot of Y and use a dotted line style. Return the three area objects in array h. The area function creates one area object for each column in Y.

Y = [1, 5, 3;
     3, 2, 7;
     1, 5, 3;
     2, 6, 1];
h = area(Y,'LineStyle',':');

Change the area colors using RGB triplet color values. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead.

h(1).FaceColor = [0 0.25 0.25];
h(2).FaceColor = [0 0.5 0.5];
h(3).FaceColor = [0 0.75 0.75];

Create an area chart that uses colormap colors by setting the FaceColor property to 'flat'.

y = [1 3 5; 3 2 7; 3 4 2];


  • If Y contains NaN values, then the area function breaks up the area around the missing values.

Introduced before R2006a

Was this topic helpful?