Documentation Center

  • Trial Software
  • Product Updates

Compare Data Sets Using Overlayed Area Graphs

This example shows how to compare two data sets by overlaying their area graphs.

Overlay Two Area Graphs

Define the sales and expenses data from the years 2004 to 2008.

years = 2004:2008;
sales = [51.6, 82.4, 90.8, 59.1, 47.0];
expenses = [19.3, 34.2, 61.4, 50.5, 29.4];

Use the area function to display sales and expenses as two separate area graphs in the same axes. First, create an area graph of sales. Change the color of the area graph by setting the FaceColor and EdgeColor properties using RGB color values.


Use the hold command to prevent a new graph from replacing the area graph of sales. Create a second area graph of expenses and change the color of this graph by specifying the FaceColor and EdgeColor properties. Set the hold state to off.

hold on
hold off

Add Grid Lines

Set the tick marks along the x-axis to correspond to whole years. Draw a grid line for each tick mark by setting the XGrid property to on. Display the grid lines on top of the area graphs by setting the Layer property to top.


Add Title, Axis Labels, and Legend

Give the figure the title, "Profit Margin for 2004 to 2008". Add axis labels for sales and years. Add a legend to the graph to indicate the areas of profits and expenses.

title('Profit Margin for 2004 to 2008')
ylabel('Expenses + Profits = Sales in 1000s')


See Also

| | |

Was this topic helpful?