MATLAB Examples

Linked Plots and Data Brushing

This video tutorial will show you how to link plots to their data sources providing a live view of a variable and how to carry out data brushing, letting you select and manipulate data graphically via a plot and allowing you to synchronize multiple views of the same data set.


Load Some Data

First we will load and plot a variable y.

load chirp;

We will dock this into the desktop for easier viewing.

If you press the Link Plot button on the figure toolbar, an information bar appears indicating that the plot is now linked and therefore any changes to its data source, in this case y, will be immediately reflected in the plot.

Change a Variable

For example, if we add some noise with...


...we see the plot update

Data Source Information

All the plots on all the axes in the figure are linked to their data sources and listed here. In this case there is just one.

When you plot interactively from the workspace browser or variable editor as we have just done the names of the data sources get added to the plot, and as a result the variables to be linked to can be known easily.

In the case of plotting commands executed programmatically, which just receive data passed in without information of the source, the workspace is searched for a variable that matches the data being passed in. If multiple matches are found, a dialog appears asking you to pick one.

Sometimes it cannot be determined automatically what the actual data source variable could be, such as here. In this case you can manually change the data source of a plot to any expression by clicking here. You can also pick from a list of 1-D arrays or columns from 2D arrays in the current worksapce.

Note that you can also use the linkdata command instead of pressing the link data button. The information bar can be hidden by clicking here.

Via The Variable Editor

Changes to a variable can also be made via the variable editor, and are therefore also reflected in the plot.


You can use this technique to monitor arrays while debugging. To do this...

  • Set a break point after the creation of the variables you are interested in monitoring and
  • Run the program
  • When the program stops at the break point you can plot your variables with a function call from the command window or via the workspace browser.
  • ...then set it to be linked
  • Now when you step through your code, or in this case stop once each time round the loop by pressing continue button you can watch the variable change like a graphical watch window, helping you understand the functioning of your code.
  • Here x is being smoothed with the filter function more each time.
  • Here we see there are currently two linked plots


Data Brushing lets you highlight or make changes to the data graphically via the plot and have these changes reflected in a variable or in other plots linked to the same variable.

We will plot the original data again.

load chirp;

To put a figure into brushing mode, enter the brush command or click here on the figure toolbar.

  • Let's say you wanted to remove the last section. We do that by selecting with the bounding box and choosing one of the actions from the context menu.
  • You can select multiple regions by holding the shift key while dragging
  • You can change the brushing color here
  • You could limit the amplitude.

With brushing enabled on its own, it is just the data inside the plot that is selected and potentially changed as it is not linked to any variables. This is useful for removing outliers or cleaning up a plot for presentation.

Brushing and Linking

While in brushing mode, if you also link the figure to its data source, then you will be modifying this variable, which can be more easily seen with the variable editor open. If we select and modify this section, we see the changes reflected here.

You can also brush in the variable editor. Note that you do not need to put the variable editor or a plot into brushing mode just view the brushing selections made by other tools. You need to put it into brushing mode only to make selections.

A Road Accident Example


By linking multiple plots that show different aspects of the same variable or multi-variate data set such as this array of US road accident fatalities for each state, you can explore relationships between the data.

Here different columns of the data have been plotted such as the location of the state, fatalities per 1000 vehicles against ave. miles per vehicle. The figures have been sets to be linked and put into brush mode.

By selecting subsets of the data in one view, such as the map plot you can see that selection reflected in the others that are highlighting different attributes. If we add a histogram (data(:,9)) of fatalities per vehicle miles


Linking the data, we see that this is an example where the source cannot be determined automatically. To resolve this you can set it manually be clicking here and specifying an expression. We will select data(:,9).

Now we can select the lower part of this histogram we can see where the low rates per fatalities per vehicle miles occur which is mainly in urban areas.


This concludes the demonstration. Try these features in MATLAB now or watch one of the other videos.