Categories &

Functions List

Function Reference: gscatter

statistics: gscatter (x, y, g)
statistics: gscatter (x, y, g, clr, sym, siz)
statistics: gscatter (…, doleg, xnam, ynam)
statistics: h = gscatter (…)

Draw a scatter plot with grouped data.

gscatter is a utility function to draw a scatter plot of x and y, according to the groups defined by g. Input x and y are numeric vectors of the same size, while g is either a vector of the same size as x or a character matrix with the same number of rows as the size of x. As a vector g can be numeric, logical, a character array, a string array (not implemented), a cell string or cell array.

A number of optional inputs change the appearance of the plot:

  • "clr" defines the color for each group; if not enough colors are defined by "clr", gscatter cycles through the specified colors. Colors can be defined as named colors, as rgb triplets or as indices for the current colormap. The default value is a different color for each group, according to the current colormap.
  • "sym" is a char array of symbols for each group; if not enough symbols are defined by "sym", gscatter cycles through the specified symbols.
  • "siz" is a numeric array of sizes for each group; if not enough sizes are defined by "siz", gscatter cycles through the specified sizes.
  • "doleg" is a boolean value to show the legend; it can be either on (default) or off.
  • "xnam" is a character array, the name for the x axis.
  • "ynam" is a character array, the name for the y axis.

Output h is an array of graphics handles to the line object of each group.

See also: scatter

Source Code: gscatter

Example: 1

 

 load fisheriris;
 X = meas(:,3:4);
 cidcs = kmeans (X, 3, "Replicates", 5);
 gscatter (X(:,1), X(:,2), cidcs, [.75 .75 0; 0 .75 .75; .75 0 .75], "os^");
 title ("Fisher's iris data");

                    
plotted figure