plotmatrix

Scatter plot matrix

Syntax

  • [H,AX,BigAx,P,PAx] = plotmatrix(___) example

Description

example

plotmatrix(X,Y) creates a matrix of subaxes containing scatter plots of the columns of X against the columns of Y. If X is p-by-n and Y is p-by-m, then plotmatrix produces an n-by-m matrix of subaxes.

example

plotmatrix(X) is the same as plotmatrix(X,X) except that the subaxes along the diagonal are replaced with histogram plots of the data in the corresponding column of X. For example, the subaxes along the diagonal in the ith column is replaced by hist(X(:,i)).

example

plotmatrix(___,LineSpec) specifies the line style, marker symbol, and color for the scatter plots. The option LineSpec can be preceded by any of the input argument combinations in the previous syntaxes.

example

[H,AX,BigAx,P,PAx] = plotmatrix(___) returns handles to the graphic objects created as follows:

  • H – Matrix of handles to the line objects used to create the scatter plots

  • AX – Matrix of handles to the individual subaxes

  • BigAx – Handle to the big axes that frames the subaxes

  • P – Vector of handles for the patch objects that create the histogram plots

  • PAx – Vector of handles to the invisible histogram axes

BigAx is left as the current axes (gca) so that a subsequent title, xlabel, or ylabel command will center text with respect to the big axes.

Examples

expand all

Create Scatter Plot Matrix with Two Matrix Inputs

Initialize the random-number generator to make the output of randn repeatable. Define X as a matrix of normally distributed pseudorandom data and Y as a matrix of integer values.

rng default
X = randn(50,3);
Y = reshape(1:150,50,3);

Create a scatter plot matrix of the columns of X against the columns of Y.

figure
plotmatrix(X,Y)

The subplot in the ith row, jth column of the figure is a scatter plot of the ith column of Y against the jth column of X.

Create Scatter Plot Matrix with One Matrix Input

Initialize the random-number generator to make the output of randn repeatable and generate a matrix of normally distributed pseudorandom data

rng default
X = randn(50,3);

Create a scatter plot matrix.

figure
plotmatrix(X)

The subplot in the ith row, jth column of the matrix is a scatter plot of the ith column of X against the jth column of X. Along the diagonal, plotmatrix creates a histogram plot of each column of X.

Specify Marker Type and Color

Initialize the random-number generator to make the output of randn repeatable. Generate a matrix of normally distributed pseudorandom data.

rng(0,'twister');
X = randn(50,3);

Create a scatter plot matrix and specify the marker type and the color for the scatter plots.

figure
plotmatrix(X,'*r')

The LineSpec option sets properties for the scatter plots. To set properties for the histogram plots, use the patch object handles.

Set Plotmatrix Properties Using Handles

Initialize the random-number generator to make the output of randn repeatable. Generate a matrix of normally distributed pseudorandom data.

rng default
X = randn(50,3);

Create a scatter plot matrix and return the object handles and the axes handles.

figure
[H,AX,BigAx,P,PAx] = plotmatrix(X);

To set properties for the scatter plots, use the handles in H. To set properties for the histograms, use the patch handles in P. To set axes properties, use the axes handles, AX, BigAx, and PAx. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead.

Set the color and marker type for the scatter plot in the lower left corner.

H(3).Color = 'g';
H(3).Marker = '*';

Set the color for the histogram plot in the lower right corner. Use the title command to title the figure.

P(3).EdgeColor = 'k';
P(3).FaceColor = 'g';
title(BigAx,'A Comparison of Data Sets')

Input Arguments

expand all

X — Data to displaymatrix

Data to display, specified as a matrix.

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

Y — Data to plot against Xmatrix

Data to plot against X, specified as a matrix.

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

LineSpec — Line style, marker symbol, and color for scatter plotsstring

Line style, marker symbol, and color for the scatter plots, specified as a string. For more information on line style, marker symbol, and color options see LineSpec.

Example: ':*r'

Data Types: char

Output Arguments

expand all

H — Line object handlesmatrix

Line object handles, returned as a matrix. This is a unique identifier, which you can use to query and modify the properties of a specific line object. The line objects are used to create the scatter plots.

AX — Subaxes handlesmatrix

Subaxes handles, returned as a matrix. This is a unique identifier, which you can use to query and modify the properties of a specific subaxes.

BigAx — Big axes handlescalar

Big axes handle, returned as a scalar. This is a unique identifier, which you can use to query and modify properties of the big axes. BigAx is left as the current axes (gca) so that a subsequent title, xlabel, or ylabel command will center text with respect to the big axes.

P — Patch object handlesvector | []

Patch object handles, returned as a vector or []. If histogram plots are created, then P is returned as a vector of patch object handles for the histogram plots. These are unique identifiers, which you can use to query and modify the properties of a specific patch object. If no histogram plots are created, then P is returned as empty brackets.

PAx — Handle to invisible histogram axesvector | []

Handle to invisible histogram axes, returned as a vector or []. If histogram plots are created, then PAx is returned as a vector of histogram axes handles. These are unique identifiers, which you can use to query and modify the properties of a specific axes, such as the axes scale. If no histogram plots are created, then PAx is returned as empty brackets.

See Also

|

Was this topic helpful?