gscatter函数介绍
2016年12月26日 星期一
22:31
Syntax
gscatter(x,y,group)
gscatter(x,y,group,clr,sym,siz)
gscatter(x,y,group,clr,sym,siz,doleg)
gscatter(x,y,group,clr,sym,siz,doleg,xnam,ynam)
h = gscatter(…)
Description
gscatter(x,y,group) creates a scatter plot of x and y, grouped by group. x and y are vectors of the same size. group is a grouping variable in the form of a categorical variable, vector, string array, or cell array of strings. Alternatively, group can be a cell array containing several grouping variables (such as {g1 g2 g3}), in which case observations are in the same group if they have common values of all grouping variables. Points in the same group and appear on the graph with the same marker and color.
gscatter(x,y,group,clr,sym,siz) specifies the color, marker type, and size for each group. clr is either a string array of colors recognized by the plot function or a three-column matrix of color specifications. sym is a string array of symbols recognized by the plot command, with the default value ’.’. siz is a vector of sizes, with the default determined by the ’DefaultLineMarkerSize’ property. If you do not specify enough values for all groups, gscatter cycles through the specified values as needed.
gscatter(x,y,group,clr,sym,siz,doleg) controls whether a legend is displayed on the graph (doleg is ’on’, the default) or not (doleg is ’off’).
gscatter(x,y,group,clr,sym,siz,doleg,xnam,ynam) specifies the name to use for the x-axis and y-axis labels. If the x and y inputs are simple variable names and xnamand ynam are omitted, gscatter labels the axes with the variable names.
h = gscatter(…) returns an array of handles to the lines on the graph.
Examples
collapse all
Scatter Plot of Climate and Housing Ratings
Load the sample data.
load discrim
The sample data contains ratings of cities according to nine factors such as climate, housing, education, and health in the matrix ratings .
Plot the relationship between the ratings for climate (first column) and housing (second column) grouped by city size in the matrix group. Choose different colors and plotting symbols for each group.
figure;
gscatter(ratings(:,1),ratings(:,2),group,’br’,’xo’)
xlabel(‘climate’);
ylabel(‘housing’);
已使用 Microsoft OneNote 2016 创建。