Main Content

glyphplot

    Description

    glyphplot(X) creates a glyph plot from the multivariate data in the matrix 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).

    example

    glyphplot(X,Glyph="face") creates a Chernoff face plot from the data in 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.

    example

    glyphplot(X,Glyph="face",Features=features) creates a face plot where element i of features defines the facial feature represented by column i of X. For more information on the facial features displayed, see Facial Features.

    example

    glyphplot(___,Name=Value) 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 X before plotting.

    example

    glyphplot(fig,___) plots into the figure specified by fig instead of the current figure (gcf). (since R2024a)

    g = glyphplot(___) returns an array of Line and Text objects. Use g to query or modify the properties (Line Properties or Text Properties) of an object after you create it.

    example

    Examples

    collapse all

    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")

    Figure contains an axes object. The axes object with title Glyph Plots for Iris Data contains 450 objects of type line, text.

    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")

    Figure contains an axes object. The axes object with title Box Plots for Iris Data contains 3 objects of type boxchart. These objects represent Irises 1-50, Irises 51-100, Irises 101-150.

    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 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")

    Figure contains an axes object. The axes object contains 279 objects of type line, text.

    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])

    Figure contains an axes object. The axes object contains 297 objects of type line, text.

    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 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])

    Figure contains an axes object. The axes object contains 279 objects of type line, text.

    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")

    Figure contains 2 axes objects. Axes object 1 with title First Set of Stars contains 12 objects of type line, text. Axes object 2 with title Second Set of Stars contains 12 objects of type line, text.

    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")

    Figure contains an axes object and an object of type uicontrol. The axes object contains 279 objects of type line, text.

    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

    Figure contains an axes object. The axes object contains 8 objects of type line.

    When you specify the location of the glyph centers, the glyph plot does not include observation labels.

    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);

    Figure contains an axes object. The axes object contains 36 objects of type line, text.

    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";

    Figure contains an axes object. The axes object contains 36 objects of type line, text.

    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";

    Figure contains an axes object. The axes object contains 36 objects of type line, text. One or more of the lines displays its values using only markers

    The face corresponding to flower 51 has a purple face, light blue eyes, and a bold label.

    Input Arguments

    collapse all

    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

    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

    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.

    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

    Pages of glyphs to display, specified as a numeric vector, "all", or "scroll".

    • If Page is a numeric vector, then glyphplot displays the specified pages in succession when you press Enter.

    • If Page is "all", then glyphplot displays all pages in succession when you press Enter.

    • If Page is "scroll", then glyphplot 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

    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

    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

    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

    Method for standardizing data before plotting, specified as one of the values in this table.

    ValueDescription
    "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

    collapse all

    Objects to use for plot modification, returned as an array of Line and Text objects.

    • For a star plot, g(:,1) contains Line objects for the star perimeters, and g(:,2) contains Line objects for the spokes.

    • For a face plot, g(:,1) contains Line objects for all facial features excluding the eyes, and g(:,2) contains Line objects for the eyes.

    g(:,3) contains Text objects for any labels present.

    More About

    collapse all

    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.

    ColumnFacial 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 R2006a

    expand all