Statistical scatter plots

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


plot::Scatterplot([x1, x2, …], [y1, y2, …], <a = amin .. amax>, options)
plot::Scatterplot([[x1, x2, …], [y1, y2, …]], <a = amin .. amax>, options)
plot::Scatterplot([x1, y1], [x2, y2], …, <a = amin .. amax>, options)
plot::Scatterplot([[x1, y1], [x2, y2], …], <a = amin .. amax>, options)
plot::Scatterplot(A, <a = amin .. amax>, options)
plot::Scatterplot(s, <c1, c2>, <a = amin .. amax>, options)


plot::Scatterplot creates a scatter plot of two discrete data samples [x1, x2, …] and [y1, y2, …]. A scatter plot displays the collection of points with coordinates [x1, y1], [x2, y2] etc.

In addition, a regression line y = a + bx through the given data pairs [x1, y1] etc. is computed and added to the plot. The estimators a, b of the regression are computed by stats::linReg.

The regression line can be suppressed by specifying the attribute LinesVisible = FALSE.

The samples [x1, x2, ] and [y1, y2, ] should have the same number of elements. Otherwise, superflous elements in the longer list are ignored.

There is an ambiguity between the various input formats if only 2 data points are provided:


For two data points the calls plot::Scatterplot([a, b], [c, d]) and plot::Scatterplot([[a, b], [c, d]]) both yield plots of the two points (x1, y1) = (a, b) and (x2, y2) = (c, d), not of the points (x1, y1) = (a, c) and (x2, y2) = (b, d)!

The routines plot::Listplot and plot::PointList2d have a similar functionality. The main additional feature of plot::Scatterplot is the regression line.

Scatter plots are useful to visualize the relationship between two variables x (the “predictor”) and y (the “criterion”).

The variable regarded as a predictor corresponds to the horizontal axis while the variable regarded as the criterion corresponds to the vertical axis. The criterion variable represents the behavior to be predicted. The predictor variable represents the activity which is believed to be associated with the criterion.

The scatter plot consists of points (x, y) where x is a predictor value and y is the corresponding value of the criterion.

If there is a linear relation y = a + bx between x and y, the data points should form a line, potentially marred by statistical deviations. The regression line provided by the scatter plot allows a visual test of such a relation between x and y.


AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
AntiAliasedantialiased lines and points?TRUE
Datathe (statistical) data to plot 
Framesthe number of frames in an animation50
Legendmakes a legend entry 
LegendTextshort explanatory text for legend 
LegendEntryadd this object to the legend?FALSE
LineColorcolor of linesRGB::Red
LineWidthwidth of lines0.35
LineStylesolid, dashed or dotted lines?Solid
LinesVisiblevisibility of linesTRUE
Namethe name of a plot object (for browser and legend) 
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
PointSizethe size of points1.5
PointColorthe color of pointsRGB::Black
PointStylethe presentation style of pointsFilledCircles
PointsVisiblevisibility of mesh pointsTRUE
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title 
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles 
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component 
TitlePositionYposition of object titles, y component 
VisibleAfterobject visible after this time value 
VisibleBeforeobject visible until this time value 
VisibleFromToobject visible during this time range 
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE


Example 1

We plot some data samples:

xdata := [6, 9, 17,  0, 13, 9, 9, 12, 12, 12]:
ydata := [7, 8, 20,  2, 11, 8, 9, 12, 13, 15]:
b := plot::Scatterplot(xdata, ydata):

We can modify the appearance of the scatter plot in various ways:

b::PointColor := RGB::Red:
b::PointSize := 3*unit::mm:
b::LineColor := RGB::Black:
b::LineWidth := 1*unit::mm:

delete xdata, ydata, b:

Example 2

We analyze the relationship between the time students spent on preparing for a test and the result of the test. We collect the data in a matrix. Each row corresponds to a student. The first column describes the numbers of hours spent for the preparation, the second column contains the corresponding test score (points out of 100):

TimesAndScores := matrix([[ 1,  61], 
                          [10,  75], 
                          [4,   55],
                          [3,   18],
                          [4,   77], 
                          [6,   72],
                          [3,   18],
                          [1,   25], 
                          [0,   50],
                          [4,   68],
                          [4,   68], 
                          [8,   87],
                          [9,   74],
                          [11,  79],
                          [6,   28],
                          [4,   65], 
                          [7,   52],
                          [8,   78],
                          [2,   36], 
                          [3,   48],
                          [4,   39]

We draw a scatter plot to identify a possible relationship between the two variables:


There seems to be a relationship, indeed.

delete TimesAndScores:


x1, y1, x2, y2, …

The statistical data: numerical real values or arithmetical expressions of the animation parameter a.

x1, y1, x2, y2, … is equivalent to the attribute Data.


An array of domain type DOM_ARRAY or a matrix of category Cat::Matrix (e.g., of type matrix or densematrix) providing numerical real values or arithmetical expressions of the animation parameter a. The i-th row is regarded as the data point (xi, yi). The array/matrix must have 2 columns. If more columns are provided, the superfluous columns are ignored.

A is equivalent to the attribute Data.


A data collection of domain type stats::sample. The columns in s are regarded as x- and y-values, respectively.

s is equivalent to the attribute Data.

c1, c2

Column indices into s: positive integers. These indices, if given, indicate that only the specified columns in s should be used. If no column indices are specified, the first two columns in s are used as x and y-values, respectively.


Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.