Scatter - Scatter chart appearance and behavior - MATLAB (original) (raw)

Scatter Properties

Scatter chart appearance and behavior

Scatter properties control the appearance and behavior of Scatter object. By changing property values, you can modify certain aspects of the scatter chart. Use dot notation to query and set properties.

s = scatter(1:10,1:10); m = s.Marker; s.Marker = '*';

Markers

expand all

Marker symbol, specified as one of the options listed in this table:

Marker Description Resulting Marker
"o" Circle Sample of circle marker
"+" Plus sign Sample of plus sign marker
"*" Asterisk Sample of asterisk marker
"." Point Sample of point marker
"x" Cross Sample of cross marker
"_" Horizontal line Sample of horizontal line marker
"|" Vertical line Sample of vertical line marker
"square" Square Sample of square marker
"diamond" Diamond Sample of diamond marker
"^" Upward-pointing triangle Sample of upward-pointing triangle marker
"v" Downward-pointing triangle Sample of downward-pointing triangle marker
">" Right-pointing triangle Sample of right-pointing triangle marker
"<" Left-pointing triangle Sample of left-pointing triangle marker
"pentagram" Pentagram Sample of pentagram marker
"hexagram" Hexagram Sample of hexagram marker
"none" No markers Not applicable

Marker edge transparency, specified as a scalar in the range [0,1] or 'flat'. A value of 1 is opaque and 0 is completely transparent. Values between 0 and 1 are semitransparent.

To set the edge transparency to a different value for each point in the plot, set theAlphaData property to a vector the same size as theXData property, and set theMarkerEdgeAlpha property to 'flat'.

Marker face transparency, specified as a scalar in the range[0,1] or 'flat'. A value of 1 is opaque and 0 is completely transparent. Values between 0 and 1 are semitransparent.

To set the marker face transparency to a different value for each point in the plot, set the AlphaData property to a vector the same size as the XData property, and set theMarkerFaceAlpha property to'flat'.

Transparency data for each plotted point, specified as an array the same size as theXData property. After specifying the values, set theMarkerFaceAlpha and MarkerEdgeAlpha properties to control the type of transparency. If theMarkerFaceAlpha and MarkerEdgeAlpha properties are both set to scalar values, then the Scatter object does not use the AlphaData values.

The AlphaDataMapping property determines how theScatter object interprets the AlphaData property values.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Control how the AlphaData property is set, specified as one of these values:

Color and Size Data

expand all

Marker colors, specified as one of these values:

Example: [1 0 0; 0 1 0; 0 0 1]

Control how the CData property is set, specified as one of these values:

Variable linked to CData, specified as a character vector or string containing a MATLAB workspace variable. MATLAB evaluates the variable in the base workspace to generate theCData.

By default, there is no linked variable so the value is an empty character vector. If you link a variable, then MATLAB does not update the CData values immediately. To force an update of the data values, use the refreshdata function.

Note

If you change one data source property to a variable that contains data of a different dimension, you might cause the function to generate a warning and not render the graph until you have changed all data source properties to appropriate values.

Series index, specified as a positive whole number or "none". This property is useful for reassigning the marker colors of Scatter objects so that they match the colors of other objects. By default, theSeriesIndex property is a number that corresponds to the object's order of creation, starting at 1.

MATLAB uses the number to calculate indices for assigning colors when you call plotting functions. The indices refer to the rows of the arrays stored in theColorOrder property of the axes. The marker colors change when you change the Scatter object's SeriesIndex value, or when you change ColorOrder property of the axes.

A SeriesIndex value of"none" corresponds to a neutral color that does not participate in the indexing scheme. (since R2023b)

How Manual Color Assignment Overrides SeriesIndex Behavior

To manually control the fill color of the markers, use either of these approaches:

Manually controlling the edge colors of the markers works the same way, except that you set MarkerEdgeColor property to a color value or"flat".

When you manually set the color of an object, MATLAB disables automatic color selection for that object and allows your color to persist, regardless of the value of the SeriesIndex property. The CDataMode property indicates whether theCData colors have been set manually (by you) or automatically. A value of "manual" indicates manual selection, and a value of "auto" indicates automatic selection.

Automatic color selection is disabled when you perform either of these actions:

To enable automatic selection again, set the MarkerFaceColor,MarkerEdgeColor, or both properties to"flat". Set the CDataMode property to"auto", and set the SeriesIndex property to a positive whole number.

In some cases, MATLAB sets the SeriesIndex value to0, which also disables automatic color selection.

Marker sizes, specified in one of these forms:

Specify the values in point units, where one point equals 1/72 inch. To specify a marker that has an area of one square inch, use a value of 72^2.

Example: 50

Control how the SizeData property is set, specified as one of these values:

Variable linked to SizeData, specified as a character vector or string containing a MATLAB workspace variable. MATLAB evaluates the variable in the base workspace to generate theSizeData.

By default, there is no linked variable so the value is an empty character vector. If you link a variable, then MATLAB does not update the SizeData values. To force an update of the data values, use the refreshdata function.

Note

If you change one data source property to a variable that contains data of a different dimension, you might cause the function to generate a warning and not render the graph until you have changed all data source properties to appropriate values.

Cartesian Coordinate Data

expand all

x values, specified as a scalar or a vector. The scatter plot displays an individual marker for each value inXData.

The input argument x to the plotting function sets the_x_ values. XData andYData must have equal lengths.

Example: [1 2 4 2 6]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Control how the XData property is set, specified as one of these values:

y values, specified as a scalar or a vector. The scatter plot displays an individual marker for each value inYData.

The input argument y to the plotting function sets the_y_ values. XData andYData must have equal lengths.

Example: [1 3 3 4 6]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Control how the YData property is set, specified as one of these values:

z values, specified as a scalar or a vector.

Example: [1 2 2 1 0]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Control how the ZData property is set, specified as one of these values:

Type of jitter (spacing of points) along the _x_-dimension, specified as one of the following values:

Maximum amount of jitter (offset between points) along the _x_-dimension, specified as a nonnegative scalar value in data units.

For example, to set the jitter width to 90% of the shortest distance between adjacent points, take the minimum distance between unique values of x and scale by0.9.

XJitterWidth = 0.9 * min(diff(unique(x)));

Since R2025a

Direction of jitter along the _x_-dimension, specified as one of these values:

Type of jitter (spacing of points) along the _y_-dimension, specified as one of the following values:

Maximum amount of jitter (offset between points) along the_y_-dimension, specified as a nonnegative scalar value in data units.

For example, to set the jitter width to 90% of the shortest distance between adjacent points, take the minimum distance between unique values of y and scale by0.9.

YJitterWidth = 0.9 * min(diff(unique(y)));

Since R2025a

Direction of jitter along the _y_-dimension, specified as one of these values:

Type of jitter (spacing of points) along the _z_-dimension, specified as one of the following values:

Maximum amount of jitter (offset between points) along the _z_-dimension in data units, specified as a nonnegative scalar value.

For example, to set the jitter width to 90% of the shortest distance between adjacent points, take the minimum distance between unique values ofz and scale by0.9.

ZJitterWidth = 0.9 * min(diff(unique(z)));

Since R2025a

Direction of jitter along the _z_-dimension, specified as one of these values:

Polar Coordinate Data

expand all

Radius values, specified as a vector. ThetaData andRData must be vectors of equal length.

This property applies only to polar axes.

Control how the RData property is set, specified as one of these values:

Variable linked to RData, specified as a character vector or string containing a MATLAB workspace variable name. MATLAB evaluates the variable in the base workspace to generate theRData.

By default, there is no linked variable so the value is an empty character vector, ''. If you link a variable, then MATLAB does not update the RData values immediately. To force an update of the data values, use the refreshdata function.

Note

If you change one data source property to a variable that contains data of a different dimension, you might cause the function to generate a warning and not render the graph until you have changed all data source properties to appropriate values.

This property applies only to polar axes.

Angle values, specified as a vector. ThetaData andRData must be vectors of equal length.

This property applies only to polar axes.

Control how the ThetaData property is set, specified as one of these values:

Variable linked to ThetaData, specified as a character vector or string containing a MATLAB workspace variable name. MATLAB evaluates the variable in the base workspace to generate theRData.

By default, there is no linked variable so the value is an empty character vector, ''. If you link a variable, then MATLAB does not update the ThetaData values immediately. To force an update of the data values, use the refreshdata function.

Note

If you change one data source property to a variable that contains data of a different dimension, you might cause the function to generate a warning and not render the graph until you have changed all data source properties to appropriate values.

This property applies only to polar axes.

Geographic Coordinate Data

expand all

Latitude values, specified as a vector. LatitudeData and LongitudeData must be vectors of equal length.

This property applies only to geographic axes.

Control how the LatitudeData property is set, specified as one of these values:

This property applies only to geographic axes.

Variable linked to LatitudeData, specified as a character vector or string containing a MATLAB workspace variable name. MATLAB evaluates the variable in the base workspace to generate theRData.

By default, there is no linked variable so the value is an empty character vector, ''. If you link a variable, MATLAB does not update the LatitudeData values immediately. To force an update of the data values, use the refreshdata function.

Note

If you change one data source property to a variable that contains data of a different dimension, you might cause the function to generate a warning and not render the graph until you have changed all data source properties to appropriate values.

This property applies only to geographic axes.

Longitude values, specified as a vector.LongitudeData and LatitudeData must be vectors of equal length.

This property applies only to geographic axes.

Control how the LongitudeData property is set, specified as one of these values:

This property applies only to geographic axes.

Variable linked to LongitudeData, specified as a character vector or string containing a MATLAB workspace variable name. MATLAB evaluates the variable in the base workspace to generate theRData.

By default, there is no linked variable so the value is an empty character vector, ''. If you link a variable, MATLAB does not update the LatitudeData values immediately. To force an update of the data values, use the refreshdata function.

Note

If you change one data source property to a variable that contains data of a different dimension, you might cause the function to generate a warning and not render the graph until you have changed all data source properties to appropriate values.

This property applies only to geographic axes.

Table Data (Since R2021b)

expand all

Source table containing the data to plot, specified as a table or timetable.

Table variable containing the _x_-coordinates, specified using one of the indexing schemes from the following table. The variable you specify can contain numeric, categorical, datetime, or duration values. When you set this property, MATLAB updates the XData property.

This table lists the different indexing schemes you can use to specify the table variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Table variable containing the _y_-coordinates, specified using one of the indexing schemes from the following table. The variable you specify can contain numeric, categorical, datetime, or duration values. When you set this property, MATLAB updates the YData property.

This table lists the different indexing schemes you can use to specify the table variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Table variable containing the _z_-coordinates, specified using one of the indexing schemes from the following table. The variable you specify can contain numeric, categorical, datetime, or duration values. When you set this property, MATLAB updates the ZData property.

This table lists the different indexing schemes you can use to specify the table variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Table variable containing the radius values, specified using one of the indexing schemes from the following table. The variable you specify can contain any type of numeric values. When you set this property, MATLAB updates the RData property.

Here is a list of the different indexing schemes you can use to specify the table variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Table variable containing the angle values, specified using one of the indexing schemes from the following table. The variable you specify can contain any type of numeric values. When you set this property, MATLAB updates the ThetaData property.

Here is a list of the different indexing schemes you can use to specify the table variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Table variable containing the latitude values for geographic plots, specified using one of the indexing schemes from the following table. When you set this property, MATLAB updates the LatitudeData property.

Here is a list of the different indexing schemes you can use to specify the table variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Table variable containing the longitude values for geographic plots, specified using one of the indexing schemes from the following table. When you set this property, MATLAB updates the LongitudeData property.

Here is a list of the different indexing schemes you can use to specify the table variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Table variable containing marker size data, specified as a variable index into the source table.

Specifying the Table Index

Use any of the following indexing schemes to specify the desired variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Specifying Size Data

The variable you specify can contain any numeric type. When you set theSizeVariable property, MATLAB updates the SizeData property.

Table variable containing the color data, specified as a variable index into the source table.

Specifying the Table Index

Use any of the following indexing schemes to specify the desired variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Specifying Color Data

Specifying the ColorVariable property controls the colors of the markers. The data in the variable controls the marker fill color when theMarkerFaceColor property is set to"flat". The data can also control the marker outline color, when the MarkerEdgeColor is set to"flat".

The table variable you specify can contain values of any numeric type. The values can be in either of the following forms:

When you set the ColorVariable property, MATLAB updates the CData property.

Table variable containing transparency data, specified as a variable index into the source table.

Specifying the Table Index

Use any of the following indexing schemes to specify the desired variable.

Indexing Scheme Examples
Variable name:A string scalar or character vector.A pattern object. The pattern object must refer to only one variable. "A" or 'A' — A variable named A"Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit
Variable index:An index number that refers to the location of a variable in the table.A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values. 3 — The third variable from the table[false false true] — The third variable
Variable type:A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable. vartype("double") — The variable containing double values

Specifying Transparency Data

The data in the variable you specify controls the transparency of the markers. Smaller values are more transparent, and larger values are more opaque. The values can be any numeric type.

After setting the AlphaVariable property, set the MarkerFaceAlpha and MarkerEdgeAlpha properties to control the type of transparency. If the MarkerFaceAlpha and MarkerEdgeAlpha properties are both set to scalar values, then the scatter object does not use the data from the table.

When you set this property, MATLAB updates the AlphaData property.

Legend

expand all

Legend label, specified as a character vector or string scalar. The legend does not display until you call the legend command. If you do not specify the text, then legend sets the label using the form'dataN'.

Interactivity

expand all

Data tip content, specified as a DataTipTemplate object. You can control the content that appears in a data tip by modifying the properties of the underlying DataTipTemplate object. For a list of properties, seeDataTipTemplate Properties.

For an example of modifying data tips, see Create Custom Data Tips.

Note

The DataTipTemplate object is not returned byfindobj or findall, and it is not copied by copyobj.

Callbacks

Callback Execution Control

expand all

This property is read-only.

Parent/Child

expand all

Parent, specified as an Axes,PolarAxes, Group, orTransform object.

Identifiers

expand all

This property is read-only.

Type of graphics object, returned as 'scatter'. Use this property to find all objects of a given type within a plotting hierarchy, for example, searching for the type using findobj.

Object identifier, specified as a character vector or string scalar. You can specify a unique Tag value to serve as an identifier for an object. When you need access to the object elsewhere in your code, you can use the findobj function to search for the object based on the Tag value.

Version History

Introduced before R2006a

expand all

Set the XJitterDirection,YJitterDirection, and ZJitterDirection properties to control the direction of the jitter in your chart. Each of these properties can have a value of "negative","positive", or "both".

Opt out of automatic color selection for Scatter objects by setting theSeriesIndex property to "none". When you specify"none", the Scatter object has a neutral color.

To enable automatic color selection again, set the SeriesIndex property to a positive whole number.

Control how Scatter objects vary in color by setting theSeriesIndex property. This property is useful when you want to match the colors of different objects in the axes.

Setting or getting UIContextMenu property is not recommended. Instead, use the ContextMenu property, which accepts the same type of input and behaves the same way as theUIContextMenu property.

There are no plans to remove the UIContextMenu property, but it is no longer listed when you call the set, get, orproperties functions on the Scatter object.