brush

Interactively mark data values in a chart

Description

Data brushing allows you to mark data values in a chart using a color of your choice. You can mark individual data values, or select many values to mark using a selection rectangle. Once you have values marked, you can delete them or save them to a variable in the workspace. Brush marks will persist until you remove them, even if you pan, zoom, add data tips, or edit the plot.

Most charts support data brushing, including line, bar, area, histogram, and surface charts. Charts that support brushing typically display the brush icon in the axes toolbar.

Creation

Description

example

brush on turns on brushing in the current figure. With brushing on, mark a single data value by clicking on it. Mark multiple data values by dragging a selection rectangle around them. To add additional marks or remove unwanted marks, hold the Shift key while brushing the values.

brush off turns off brushing. If there are existing brush marks on the chart, this command will not remove them.

brush toggles the brushing mode between 'on' and 'off'.

brush(color) sets the color for subsequent brush marks. Setting the brush color does not affect current marks unless you brush data, change the brush color, and then add or remove marks using the Shift key. In this case, all marks update to the new color.

brush(fig,___) sets brush mode or color options for the specified figure. For example, brush(fig,'on').

example

b = brush(___) creates a brush object. This syntax is useful for controlling the brush mode, color, and callback properties.

Input Arguments

expand all

Target figure, specified as a Figure object. If you do not specify the figure, then brushing affects the current figure.

Brush mark color, specified as an RGB triplet or a color name. To create brush marks of a certain color, set the color property before brushing your data values. Setting the brush color does not affect current marks unless you brush data, change the brush color, and then add or remove marks using the Shift key. In this case, all marks update to the new color.

An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and their equivalent RGB triplet values.

Color NameShort NameRGB TripletAppearance
'red''r'[1 0 0]

'green''g'[0 1 0]

'blue''b'[0 0 1]

'cyan' 'c'[0 1 1]

'magenta''m'[1 0 1]

'yellow''y'[1 1 0]

'black''k'[0 0 0]

'white''w'[1 1 1]

Here are the RGB triplets for the default colors MATLAB® uses in many types of plots.

RGB TripletAppearance
[0 0.4470 0.7410]

[0.8500 0.3250 0.0980]

[0.9290 0.6940 0.1250]

[0.4940 0.1840 0.5560]

[0.4660 0.6740 0.1880]

[0.3010 0.7450 0.9330]

[0.6350 0.0780 0.1840]

Properties

expand all

Brush mark color, specified as an RGB triplet or a color name. To create brush marks of a certain color, set the color property before brushing your data values. Setting the brush color does not affect current marks unless you brush data, change the brush color, and then add or remove marks using the Shift key. In this case, all marks update to the new color.

An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and their equivalent RGB triplet values.

Color NameShort NameRGB TripletAppearance
'red''r'[1 0 0]

'green''g'[0 1 0]

'blue''b'[0 0 1]

'cyan' 'c'[0 1 1]

'magenta''m'[1 0 1]

'yellow''y'[1 1 0]

'black''k'[0 0 0]

'white''w'[1 1 1]

Here are the RGB triplets for the default colors MATLAB uses in many types of plots.

RGB TripletAppearance
[0 0.4470 0.7410]

[0.8500 0.3250 0.0980]

[0.9290 0.6940 0.1250]

[0.4940 0.1840 0.5560]

[0.4660 0.6740 0.1880]

[0.3010 0.7450 0.9330]

[0.6350 0.0780 0.1840]

Brushing mode, specified as 'off' or 'on'.

Function to execute before brushing, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • Character vector that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code as you start brushing a graph. If you specify this property using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • figure — Figure object you are brushing.

  • axesStruct — Structure that contains the axes you are brushing. This structure has one field, Axes, the axes object you are brushing. If you do not use this argument in your callback function, then replace it with the tilde character (~).

For more information about how to use function handles to define callback definitions, see Callback Definition.

Function to execute after brushing, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • Character vector that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code after you finish brushing a graph. If you specify this property using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • figure — Figure object you are brushing.

  • axesStruct — Structure that contains the axes you are brushing. This structure has one field, Axes, the axes object you are brushing. If you do not use this argument in your callback function, then replace it with the tilde character (~).

For more information about how to use function handles to define callback definitions, see Callback Definition.

Brush suppression callback, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • Character vector that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to suppress brushing under conditions that you define. A numeric or logical output of 1 (true) suppresses the brush action, and a numeric or logical output of 0 (false) allows the brush action to proceed. If you specify this property using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • axes — The axes object you are brushing.

  • eventData — Empty argument. Replace it with the tilde character (~) in the function definition to indicate that this argument is not used.

If you specify this property using a function handle, then you must assign the function's output to a variable.

For more information about how to use function handles to define callback definitions, see Callback Definition.

This property is read-only.

Figure object in which brush marks appear.

Examples

collapse all

Use brushing to mark data values in a scatter plot. First, plot random x and y values. Then, turn on brushing and use the mouse to drag a rectangle around some points.

x = rand(20,1);
y = rand(20,1);
scatter(x,y);
brush('on')

To modify which points you have marked without discarding the entire set, hold down the Shift key while brushing. Add or remove a single point by clicking on it. Add or remove several points by dragging a selection rectangle.

Clear all brush marks by clicking or dragging in an empty area of the axes.

Plot data values in a bar chart and create a brush object. Then, enable brushing and set the brush color to 'green' by updating the object's properties. Finally, mark data values by including the maximum value of each bar in the selection rectangle.

y = [75 91 105 123.5 131 150 179 203 226 249 281.5];
bar(y)
b = brush;
b.Enable = 'on';
b.Color = 'green';

Save brushed data in a variable by using the context menu. First, plot some x and y values. Turn on brushing, and then mark some data values.

x = linspace(0,5,30);
y = exp(x);
plot(x,y)
brush('on')

To store the brushed data in a variable, right-click on a brushed data value and select Create Variable from the context menu. When prompted, enter the variable name. In this case, use the name bData. Finally, view the contents of bData.

bData
bData =

    3.2759   26.4660
    3.4483   31.4461
    3.6207   37.3633
    3.7931   44.3940
    3.9655   52.7475
    4.1379   62.6730
    4.3103   74.4662
    4.4828   88.4784
    4.6552  105.1273

Remove brushed data from a chart by using the context menu. First, plot some x and y values. Turn on brushing, and then mark some data values.

x = linspace(0,5,30);
y = exp(x);
scatter(x,y)
brush('on')

To remove the brushed data from the chart, right-click on a brushed data value and select Remove from the context menu.

More About

expand all

Tips

  • To brush a histogram chart, you must first turn on data linking.

Introduced in R2008a