glyphplot
Glyph plot
Syntax
Description
glyphplot(
creates a glyph plot from the
multivariate data in the matrix X
)X
. By default,
glyphplot
creates a star plot. A star plot represents each
observation as a star, in which spoke i is proportional in length to the
value of variable i for that observation. By default,
glyphplot
standardizes the columns of X
before
plotting.
Note that the syntax glyphplot(X,Glyph="star")
is equivalent to the
syntax glyphplot(X)
.
glyphplot(
creates a Chernoff
face plot from the data in X
,Glyph="face")X
. A Chernoff face plot represents each
observation as a face, in which facial feature i is displayed with a
characteristic proportional to the value of variable i for that
observation. For more information on the facial features displayed, see Facial Features.
glyphplot(
creates a face plot where element i of X
,Glyph="face",Features=features
)features
defines the facial feature represented by column i of
X
. For more information on the facial features displayed, see Facial Features.
glyphplot(___,
specifies options using one or more name-value arguments in addition to any of the input
argument combinations in previous syntaxes. For example, you can use principal component
analysis (PCA) to standardize the data in Name=Value
)X
before plotting.
returns an
array of g
= glyphplot(___)Line
and Text
objects. Use g
to query or modify the properties (Line Properties or Text Properties) of an object after you
create it.
Examples
Visualize Data Using Star Plot
Visualize multidimensional data by using a star plot. Notice how the stars differ across the observations.
Load the fisheriris
data set, which contains four measurements (sepal length, sepal width, petal length, and petal width) from three species of iris flowers.
load fisheriris
The matrix meas
contains all four measurements for 150 flowers. Display the measurements for the first eight flowers.
head(meas)
5.1000 3.5000 1.4000 0.2000 4.9000 3.0000 1.4000 0.2000 4.7000 3.2000 1.3000 0.2000 4.6000 3.1000 1.5000 0.2000 5.0000 3.6000 1.4000 0.2000 5.4000 3.9000 1.7000 0.4000 4.6000 3.4000 1.4000 0.3000 5.0000 3.4000 1.5000 0.2000
Create a glyph plot using the iris measurements in meas
. By default, glyphplot
creates a star plot and standardizes the measurements before plotting.
glyphplot(meas)
title("Glyph Plots for Iris Data")
Each star corresponds to an iris, and each spoke corresponds to one of the standardized iris measurements. The length of a spoke indicates the relative value of the measurement.
Notice that the first 50 flowers tend to have smaller stars than the next 50 flowers. Similarly, both of those sets of flowers tend to have smaller stars than the last 50 flowers.
Compare the distribution of the measurements for the three sets of irises by using box plots.
figure boxchart(meas(1:50,:)) hold on boxchart(meas(51:100,:)) boxchart(meas(101:end,:)) hold off legend(["Irises 1-50","Irises 51-100","Irises 101-150"]) xticklabels(["Sepal Length","Sepal Width","Petal Length","Petal Width"]) title("Box Plots for Iris Data")
The box plots show that, for three of the four measurements, the first 50 irises tend to have smaller values than the next 50 irises, and those irises tend to have smaller values than the last 50 irises. Because smaller values correspond to shorter star spokes, this result helps explain the relative size of the stars in the previous star plot.
Visualize Data Using Face Plot
Visualize multidimensional data by using a Chernoff face plot. Specify the facial features corresponding to the data variables.
Load the carsmall
data set, which contains measurements for 100 cars. Combine the Acceleration
, Displacement
, Horsepower
, MPG
, and Weight
variables into a table. Display the values for the first 12 cars.
load carsmall
Tbl = table(Acceleration,Displacement,Horsepower,MPG,Weight);
head(Tbl,12)
Acceleration Displacement Horsepower MPG Weight ____________ ____________ __________ ___ ______ 12 307 130 18 3504 11.5 350 165 15 3693 11 318 150 18 3436 12 304 150 16 3433 10.5 302 140 17 3449 10 429 198 15 4341 9 454 220 14 4354 8.5 440 215 14 4312 10 455 225 14 4425 8.5 390 190 15 3850 17.5 133 115 NaN 3090 11.5 350 165 NaN 4142
Create a Chernoff face plot using the car measurements in Tbl
. Note that glyphplot
excludes observations with missing values from the plot and, by default, standardizes the car measurements before plotting.
glyphplot(Tbl{:,:},Glyph="face")
By default, glyphplot
uses the face size to represent the first variable (in this case, Acceleration
). The forehead-to-jaw relative arc length represents the second variable (Displacement
), the forehead shape represents the third variable (Horsepower
), the jaw shape represents the fourth variable (MPG
), and the width between the eyes represents the fifth variable (Weight
). For more information, see Facial Features.
Change the previous plot so that the MPG
variable is not displayed and the jaw shape represents the Weight
variable instead.
figure
glyphplot(Tbl{:,:},Glyph="face",Features=[1 2 3 0 4])
Because the plot does not display the MPG
variable, which contained missing values, the plot includes some of the observations omitted from the previous plot.
Specify Layout of Glyphs
Specify the layout of the glyphs in a glyph plot. You can specify the grid in which to plot the glyphs or the location of the glyph centers.
Load the carsmall
data set, which contains measurements for 100 cars. Combine the Acceleration
, Displacement
, Horsepower
, MPG
, and Weight
variables into a table. Display the values for the first 12 cars.
load carsmall
Tbl = table(Acceleration,Displacement,Horsepower,MPG,Weight);
head(Tbl,12)
Acceleration Displacement Horsepower MPG Weight ____________ ____________ __________ ___ ______ 12 307 130 18 3504 11.5 350 165 15 3693 11 318 150 18 3436 12 304 150 16 3433 10.5 302 140 17 3449 10 429 198 15 4341 9 454 220 14 4354 8.5 440 215 14 4312 10 455 225 14 4425 8.5 390 190 15 3850 17.5 133 115 NaN 3090 11.5 350 165 NaN 4142
Create a star plot using the car measurements in Tbl
. Arrange the stars into an 8-by-12 grid.
glyphplot(Tbl{:,:},Grid=[8 12])
Because the grid is 8-by-12, the plot can display at most 96 observations. In this case, the plot contains all observations in Tbl
that do not have missing values. By default, glyphplot
labels each glyph with the index of the observation in Tbl
.
Display the stars in a 2-by-2 grid. Use the Page
name-value argument to specify the set of stars to display. In this case, display the first two sets of stars.
figure tiledlayout(1,2) nexttile glyphplot(Tbl{:,:},Grid=[2 2]) title("First Set of Stars") nexttile glyphplot(Tbl{:,:},Grid=[2 2],Page=2) title("Second Set of Stars")
You can also display multiple pages in succession by specifying Page
as a numeric vector or "all"
. After the call to glyphplot
, press Enter to display the next page of glyphs.
Alternatively, display all sets of stars in one plot with a scroll bar.
glyphplot(Tbl{:,:},Grid=[2 2],Page="scroll")
Instead of creating a grid of glyphs, you can specify the location of the glyph centers.
Plot the stars for the first four cars. Standardize the data set before passing it to glyphplot
. Otherwise, the function standardizes only the four observations, instead of the entire data set, before plotting. Specify the star center locations as a matrix, with row i corresponding to the x- and y-axis values, respectively, of star center i. Specify the maximum star radius as 0.5
. To better compare the stars, add grid lines to the plot.
figure X = normalize(Tbl{:,:},"range",[0.1 0.9]); glyphplot(X(1:4,:),Centers=[1 2; 2 2; 1 1; 2 1],Radius=0.5, ... Standardize="off") grid on
When you specify the location of the glyph centers, the glyph plot does not include observation labels.
Adjust Glyph Plot Appearance
Adjust the appearance of a glyph plot by setting some plot properties in the call to glyphplot
, and by modifying the appearance of the plot after creating it.
Load the fisheriris
data set, which contains four measurements (sepal length, sepal width, petal length, and petal width) from three species of iris flowers.
load fisheriris
The matrix meas
contains all four measurements for 150 flowers. The cell array species
contains the species name for each of the 150 flowers.
Create a new variable named label
that contains the index and species name for each flower.
index = (1:150)';
label = index + "-" + species;
Create a star plot using the iris measurements in meas
, and label each star using the label
variable. Specify the color of the stars as light green. When you specify line properties (such as Color
) in the call to glyphplot
, the function sets the property values for all the glyphs in the plot. For simplicity, display flowers 49–60 in a 4-by-3 grid.
To modify the appearance of the plot after creating it, return an array of Line
and Text
objects s
.
lightGreen = [0.4660 0.6740 0.1880]; s = glyphplot(meas,ObsLabels=label, ... Color=lightGreen, ... Grid=[4 3],Page=5);
For the star corresponding to flower 51, modify the color of the star perimeter, the color of the star spokes, and the font of the star label.
purple = [0.4940 0.1840 0.5560];
lightBlue = [0.3010 0.7450 0.9330];
s(3,1).Color = purple;
s(3,2).Color = lightBlue;
s(3,3).FontWeight = "bold";
The star corresponding to flower 51 has a purple outline, light blue spokes, and a bold label.
Recreate the previous plot using a face plot instead of a star plot. Return and modify an array of Line
and Text
objects f
.
figure f = glyphplot(meas,Glyph="face",ObsLabels=label, ... Color=lightGreen, ... Grid=[4 3],Page=5); f(3,1).Color = purple; f(3,2).Color = lightBlue; f(3,3).FontWeight = "bold";
The face corresponding to flower 51 has a purple face, light blue eyes, and a bold label.
Input Arguments
X
— Multivariate data
numeric matrix
Multivariate data, specified as a numeric matrix. The rows of X
correspond to observations, and the columns correspond to variables.
glyphplot
does not display observations with missing
(NaN
) values in any of the plotted variables.
Example: rand(100,10)
Data Types: single
| double
features
— Variables to plot and their corresponding facial features
vector of integer values in the range [0,17]
Variables to plot and their corresponding facial features, specified as a vector of
integer values in the range [0,17]. features(i)
indicates the facial
feature for the variable X(:,i)
. For more information, see Facial Features. The length of features
must be equal to
the number of columns in X
. Specify a value of 0
for any variable you do not want to plot.
Example: [1 0 7 0]
specifies to use the size of the face to
represent the first variable and the height of the eyes to represent the third
variable.
Data Types: single
| double
fig
— Figure for plot
Figure
object
Figure for the plot, specified as a Figure
object. For more
information on creating a Figure
object, see figure
.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: glyphplot(X,Grid=[3 2],Page=5)
specifies to display the fifth
page of glyphs in a 3-by-2 layout.
Grid
— Layout for glyphs
vector of two positive integers
Layout for the glyphs, specified as a vector of two positive integers. The first value indicates the number of rows of glyphs in the plot, and the second value indicates the number of columns.
Some grid entries are empty when the number of observations is less than the
number of entries in the grid layout (that is, the product of the number of rows and
the number of columns). When the number of observations is more than the number of
grid entries, you can use the Page
name-value argument to specify
which page of glyphs to display.
Specify the layout of the glyphs by using a grid (Grid
) or
glyph centers (Centers
), but not both. For an example, see Specify Layout of Glyphs.
Example: Grid=[5 10]
Data Types: single
| double
Page
— Pages of glyphs to display
numeric vector | "all"
| "scroll"
Pages of glyphs to display, specified as a numeric vector,
"all"
, or "scroll"
.
If
Page
is a numeric vector, thenglyphplot
displays the specified pages in succession when you pressEnter
.If
Page
is"all"
, thenglyphplot
displays all pages in succession when you pressEnter
.If
Page
is"scroll"
, thenglyphplot
displays one plot with a scroll bar. Use the scroll bar to display other pages of glyphs.
glyphplot
ignores this value unless you specify the layout of
the glyphs by using a grid (Grid
).
Example: Page=2
Example: Page=1:4
Example: Page="scroll"
Data Types: single
| double
| char
| string
Centers
— Location of glyph centers
two-column numeric matrix
Location of the glyph centers, specified as a two-column numeric matrix. Each row
of Centers
corresponds to an observation in
X
. The first entry corresponds to the x-axis
coordinate of the center, and the second entry corresponds to the
y-axis coordinate.
Specify the layout of the glyphs by using a grid (Grid
) or
glyph centers (Centers
), but not both. For an example, see Specify Layout of Glyphs.
glyphplot
ignores the Centers
value when
you specify the layout of the glyphs by using a grid
(Grid
).
Example: Centers=[1 1; 1 2; 1 3; 1 4; 2 1; 2 2; 2 3; 2
4]
Data Types: single
| double
Radius
— Maximum glyph radius
positive scalar
Maximum glyph radius, specified as a positive scalar. The function scales the
glyphs so that the largest has a radius equal to the Radius
value.
glyphplot
ignores this value unless you specify the layout of
the glyphs by using glyph centers (Centers
).
Example: Radius=0.5
Data Types: single
| double
ObsLabels
— Observation labels
1:size(X,1)
(default) | character array | string array | cell array of character vectors
Observation labels, specified as a character array, string array, or cell array of
character vectors. Specify a label for each observation in X
. Use
""
or ''
for blank labels.
glyphplot
does not display observation labels when you
specify the layout of the glyphs by using glyph centers
(Centers
).
Example: ObsLabels=["iris1","iris2","iris3","iris4","iris5"]
Data Types: char
| string
| cell
Standardize
— Method for standardizing data
"column"
(default) | "matrix"
| "pca"
| "off"
Method for standardizing data before plotting, specified as one of the values in this table.
Value | Description |
---|---|
"column" | Map each column of X separately onto the interval
[0,1]. |
"matrix" | Map the entire matrix X onto the interval
[0,1]. |
"pca" | Transform X to its principal component scores, in
order of decreasing eigenvalue, and map each one onto the interval
[0,1]. |
"off" | Use unstandardized X data. Negative values in
X might make a star plot uninterpretable. |
For more information on principal component analysis, see pca
.
Example: Standardize="pca"
Data Types: char
| string
Output Arguments
g
— Objects for plot modification
array of Line
and Text
objects
Objects to use for plot modification, returned as an array of Line
and Text
objects.
For a star plot,
g(:,1)
containsLine
objects for the star perimeters, andg(:,2)
containsLine
objects for the spokes.For a face plot,
g(:,1)
containsLine
objects for all facial features excluding the eyes, andg(:,2)
containsLine
objects for the eyes.
g(:,3)
contains Text
objects for any
labels present.
More About
Facial Features
When Glyph="face"
, the columns of X
correspond
to facial features in the glyph plot. This table describes the default correspondence
between variables and facial features. You can change the correspondence by using the
features
argument. The function displays unused features at their
default values.
Column | Facial Feature |
---|---|
1 | Size of the face |
2 | Forehead-to-jaw relative arc length |
3 | Shape of the forehead |
4 | Shape of the jaw |
5 | Width between the eyes |
6 | Vertical position of the eyes |
7 | Height of the eyes |
8 | Width of the eyes — This value also affects the width of the eyebrows. |
9 | Angle of the eyes — This value also affects the angle of the eyebrows. |
10 | Vertical position of the eyebrows |
11 | Width of the eyebrows (relative to the eyes) |
12 | Angle of the eyebrows (relative to the eyes) |
13 | Direction of the pupils |
14 | Length of the nose |
15 | Vertical position of the mouth |
16 | Shape of the mouth |
17 | Mouth arc length |
Tips
You can modify certain aspects of the glyphs by specifying a property name and value for any of the properties listed in Line Properties. However, this approach applies the modification to all glyphs in the plot. To modify only certain glyphs, use the syntax that returns
Line
objects and then use dot notation to adjust each object property individually. For an example, see Adjust Glyph Plot Appearance.
Version History
Introduced before R2006aR2024a: Specify a target figure
Specify a target figure for the plot by using the fig
input
argument.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)