Graphics    

Adding Plots of Basic Statistics to Graphs

The MATLAB Data Statistics tool:

For example, the following figure includes a plot of the mean of the Predator y-data.

The following sections provide more information about using the Data Statistics tool:

Example - Plotting the Mean of a Data Set

To add a plot of the mean of a data set to a graph:

  1. Plot your data. For example, use these commands to plot historical population data from the United States census.
  2. Select the Data Statistics option from the figure window Tools menu.
  1. The Data Statistics tool calculates basic statistics on the x-data and y-data of the plot in the graph and displays the results in a dialog box.

  1. Select the statistic you want to plot in your graph by clicking in the check box next to the value.
  1. For example, to add a plot of the mean of the population data (y-data) to the graph, click in the check box next to the value (as shown in the figure). The Data Statistics tool adds the plot of the mean to the graph.

Using a Legend with Data Statistics

When you activate the Data Statistics tool, it calculates statistics for the plotted data and automatically adds a legend to the graph, if the graph doesn't already have one.

Initially, the legend only includes entries for the data sets plotted in the graph. In the legend, each data set is identified by its tag. (A tag is a user-defined text string that can be associated with any graphics object. For information about creating tags, see Identifying Objects in a Graph.) If there are data sets in the graph that do not have tags, the Data Statistics tool creates a label for them, using data 1 to identify the first plot, data 2 to identify the second plot, and so on.

When you add a plot of one or more statistics to the graph, the Data Statistics tool adds an entry in the legend for the new plot. The Data Statistics tool assigns the plotted statistic a descriptive name that identifies it in the legend. In the example, the plotted statistic has the name y mean in the legend.

Formatting Plots of Data Statistics

The Data Statistics tool uses color and line style to distinguish the plots of statistics from the other plots in a graph. However, like any other plot in a graph, you can change these characteristics.

To modify the properties of a plotted statistic:

  1. Enable plot editing mode in the figure window.
  2. Double-click on the plot of the statistic. This starts the MATLAB Property Editor, which provides access to properties of the line object used to plot the statistic.
  1. You can also access a subset of these properties by right-clicking on the plot. This brings up the plot's context menu, which includes options for specifying line width, line style, and color.

  1. Change the properties of the plot and click Apply.

Statistics Plotted by the Data Statistics Tool

The following table lists the statistics calculated by the Data Statistics tool. The table includes the name of the MATLAB function used to calculate the statistic. For more information about these statistical functions, see the "Basic Data Analysis Functions" in the "Data Analysis and Statistics" chapter.

Statistic
Description
MATLAB Function
Maximum
The largest value in the data set
max
Minimum
The smallest value in the data set
min
Mean
The average of all the values in the data set
mean
Median
The middle value in the data set
median
Range
The interval between the lowest value and the highest value in the data set. The Data Statistic tool does not plot the range statistic.
n/a
Standard deviation
A measure characterizing the amount of variation among the values in the data set
Note: The Data Statistics tool uses two lines to plot the standard deviation in a graph. The lines represent the boundaries of one standard deviation on either side of the mean of the data set.
std

Automatic Updating of Statistics

If you have the Data Statistics tool displayed and you change the x-data or y-data of a plot, the Data Statistics tool automatically regenerates the statistics for that plot.

Viewing Statistics for Multiple Plots

The Data Statistics tool calculates basic statistics for every 2-D plot in a graph, but displays the statistics for only one plot at time.

To view the statistics for a particular plot in a graph:

  1. Click the Statistics for menu in the Data Statistics dialog box.

  1. This menu lists all the data sets plotted in the graph, identifying each data set by its tag. (A tag is a user-defined text string that can be associated with any graphics object.) For plots in the graph that do not have tags, the Data Statistics tool uses data1 to identify the first plot, data2 to identify the second plot, and so on.

  1. Select a plot from the list. The Data Statistics tool updates the values displayed in the dialog box.

Saving Statistics to the MATLAB Workspace

To save the statistics generated by the Data Statistics tool to the MATLAB workspace, follow this procedure:

  1. Click the Save to Workspace button.
  2. In the Save Statistics to Workspace dialog box, specify which sets of statistics you want to save, x-data or y-data, and specify the names you want to assign to the variables in which the statistics will be stored.

The Data Statistics tool saves each set of statistics in a structure. For example, if you save the set of statistics on the x-data in the census in the variable census_dates, the contents of the structure looks like this.


  Adding Arrows and Lines to Graphs Displaying Bit-Mapped Images