主要内容

scatterhist

Scatter plot with marginal histograms

描述

example

scatterhist(x,y)在向量中创建数据的2-D散点图xandy并显示xandyas univariate histograms on the horizontal and vertical axes of the scatter plot, respectively.

example

scatterhist(x,y,姓名,Value)使用一个或多个名称值对参数指定的其他选项创建图。例如,您可以指定分组变量或更改显示选项。

example

h=散射史(___)使用先前语法中的任何输入参数,分别返回散点图,沿水平轴的直方图和沿垂直轴的直方图的三个轴手柄的向量。

例子

collapse all

加载样本数据。创建数据向量xfrom the first column of the data matrix, which contains sepal length measurements from iris flowers. Create data vectory从数据矩阵的第二列中,其中包含来自同一花的萼片宽度测量值。

loadfisheriris.mat;x = meas(:,1);y = meas(:,2);

Create a scatter plot and two marginal histograms to visualize the relationship between sepal length and sepal width.

散射史(x,y)

在直方图中显示垃圾箱的数据提示。当您将悬停在直方图中的垃圾箱上时,会出现数据提示。

The data tip displays the probability density function estimate of the selected bin and the lower and upper values for the bin edges.

加载样本数据。创建数据向量xfrom the first column of the data matrix, which contains sepal length measurements from three species of iris flowers. Create data vectory从数据矩阵的第二列中,其中包含来自同一花的萼片宽度测量值。

loadfisheriris.mat;x = meas(:,1);y = meas(:,2);

Create a scatter plot and six kernel density plots to visualize the relationship between sepal length and sepal width, grouped by species.

分散史(x,y,'Group',species,'Kernel','on')

Figure contains an axes. The axes contains 3 objects of type line. These objects represent setosa, versicolor, virginica.

The plot shows that the relationship between sepal length and width varies depending on the flower species.

加载样本数据。创建数据向量x从数据矩阵的第一列中,其中包含来自三种不同种类的虹膜花的萼片长度测量。创建数据向量y从数据矩阵的第二列中,其中包含来自同一花的萼片宽度测量值。

loadfisheriris.mat;x = meas(:,1);y = meas(:,2);

创建一个散点图和六个内核密度图,以可视化在三种由物种分组的虹膜花中测量的萼片长度和萼片宽度之间的关系。自定义图的外观。

分散史(x,y,'Group',species,'Kernel','on','Location','SouthEast',...'方向','out','颜色','kbr','linestyle',{“- - -”,'-.',':'},,...'行宽',[2,2,2],'Marker','+od','MarkerSize',[4,5,6]);

Figure contains an axes. The axes contains 3 objects of type line. These objects represent setosa, versicolor, virginica.

加载样本数据。创建数据向量xfrom the first column of the data matrix, which contains sepal length measurements from three species of iris flowers. Create data vectory从数据矩阵的第二列中,其中包含来自同一花的萼片宽度测量值。

loadfisheriris.mat;x = meas(:,1);y = meas(:,2);

Use axis handles to replace the marginal histograms with box plots.

h = scatterhist(x,y,'Group',species); holdon;clr = get(h(1),“颜色订单”); boxplot(h(2),x,species,'方向','horizontal',...'label',{'','',''},,'color',clr);Boxplot(H(3),Y,物种,'方向','horizontal',...'label', {'','',''},,'color',clr);设置(h(2:3),'XTickLabel',''); view(h(3),[270,90]);%旋转Y图axis(h(1),'auto');% Sync axesholdoff;

加载样本数据。创建数据向量xfrom the first column of the data matrix, which contains sepal length measurements from iris flowers. Create data vectory从数据矩阵的第二列中,其中包含来自同一花的萼片宽度测量值。

loadfisheririsx = meas(:,1);y = meas(:,2);

创建一个新图形并定义两个uipanelobjects to divide the figure into two parts. In the upper half of the figure, plot the sample data usingscatterhist. Include marginal kernel density plots grouped by species. In the lower half of the figure, plot a histogram of the sepal length measurements contained inx.

数字hp1 = uipanel('位置',[0 .5 1 .5]);hp2 = uipanel('位置',[0 0 1 .5]);分散史(x,y,'Group',species,'Kernel','on','Parent',hp1); axes('Parent',hp2); hist(x);

图包含2个轴和类型UIPANEL的对象。轴1包含3个类型线的对象。这些对象代表setosa,versicolor,virginica。轴2包含一个类型补丁的对象。此对象代表x。

Input Arguments

collapse all

Sample data, specified as a vector. The data vectorsxandymust be the same length.

IfxorycontainNaNvalues, thenscatterhist:

  • Removes rows withNaNvalues in eitherxory生成散点图时两个数据向量

  • Removes rows withNaN仅来自相应的值xorydata vector when generating the marginal histograms

数据类型:single|双倍的

Sample data, specified as a vector. The data vectorsxandymust be the same length.

IfxorycontainNaNvalues, thenscatterhist:

  • Removes rows withNaNvalues in eitherxory生成散点图时两个数据向量

  • Removes rows withNaN仅来自相应的值xorydata vector when generating the marginal histograms

数据类型:single|双倍的

姓名-Value Pair Arguments

Specify optional comma-separated pairs of姓名,Value参数。姓名is the argument name andValueis the corresponding value.姓名must appear inside quotes. You can specify several name and value pair arguments in any order asNAME1,Value1,...,Namen,Valuen.

例子:'Location','SouthEast','Direction','out'specifies a plot with histograms located below and to the right of the scatter plot, with the bars directed away from the scatter plot.

直方图的垃圾箱数量,指定为逗号分隔对'NBins'正整数值大于或等于2或两个此类值的向量。如果将垃圾箱的数量指定为正整数值,则该值是两个xandy直方图。如果bin的数量由向量指定,则第一个值是xdata, and the second value is the number of bins for theydata. By default, the number of bins is computed based on the sample standard deviation using Scott’s rule.

例子:'NBins',[5,7]

数据类型:single|双倍的

地点of the marginal histograms in the figure, specified as the comma-separated pair consisting of'Location'and one of the following.

'西南' Plot the histograms below and to the left of the scatter plot.
'SouthEast' Plot the histograms below and to the right of the scatter plot.
'东北' Plot the histograms above and to the right of the scatter plot.
'NorthWest' Plot the histograms above and to the left of the scatter plot.

例子:'Location','SouthEast'

边缘直方图的方向,指定为逗号分隔对'方向'and one of the following.

'in' Plot the histograms with the bars directed toward the scatter plot.
'out' 用远离散点图的条形图绘制直方图。

例子:'方向','out'

Grouping variable, specified as the comma-separated pair consisting of'Group'以及一个分类数组,逻辑或数字向量,字符数组,字符串数组或字符向量的单元格数组。分组变量中的每个唯一值都定义了一个组。

For example, ifGenderis a cell array of character vectors with values'Male'and'Female', you can useGender作为分组变量绘制数据按性别.

The number of rows in the grouping variable must be equal to the length ofx.

例子:'Group',Gender

数据类型:分类|single|双倍的|logical|char|细绳|cell

分组图指示器, specified as the comma-separated pair consisting of'PlotGroup'and one of the following.

'on' Display grouped histograms or grouped kernel density plots. This is the default if aGroupparameter is specified.
'离开' Display histograms or kernel density plots of the whole data set. This is the default if aGroupparameter is not specified.

例子:'PlotGroup','off'

直方图显示样式,指定为逗号分隔对'PlotGroup'and one of the following.

'楼梯' Display a stairstep plot that shows the outline of the histogram without filling the bars. This is the default if you specify a grouping variable that contains more than one group.
'bar' 显示直方图栏图。如果指定仅包含一个组或情节组is specified as'离开'.

例子:'Style','bar'

Kernel density plot indicator, specified as the comma-separated pair consisting of'Kernel'and one of the following.

'离开' 将边缘分布显示为直方图。
'on' Display the marginal distributions as kernel density plots.
'overlay' 显示边缘分布作为核密度图覆盖到直方图上的边缘分布,类似于历史图.

例子:'Kernel','overlay'

带宽of kernel smoothing window, specified as the comma-separated pair consisting of'Bandwidth'and a matrix of size 2-by-K, 在哪里Kis the number of unique groups. The first row of the matrix gives the bandwidth of each group inx,第二行给出了每个组的带宽y. By default,scatterhistfinds the optimal bandwidth for estimating normal densities. Specifying a different bandwidth value changes the smoothing characteristics of the resulting kernel density plot. The value specified is a scaling factor for the normal distribution used to generate the kernel density plot.

例子:'Bandwidth',[.5,.2,.1;.15,.25,.35]

数据类型:single|双倍的

传奇可见性指标, specified as the comma-separated pair consisting of'Legend'and one of the following.

'on' Set legend visible. This is the default if aGroupparameter is specified.
'离开' 设置传奇看不见。这是默认值Groupparameter is not specified.

例子:'Legend','on'

父母container for the plot, specified as auipanel容器对象或数字container object. You can create panel container objects usinguipanelor数字, respectively.

For example, ifh1是一个面板容器对象,如下指定图的父容器。

例子:'Parent',h1

Style of kernel density plot line, specified as the comma-separated pair consisting of'linestyle'and a valid line style or a string array or cell array of valid line styles. Seeplotfor valid line styles. The default is a solid line. Use a string array or cell array to specify different line styles for each group. When the total number of groups exceeds the number of specified values,scatterhistcycles through the specified values.

例子:'linestyle',{'-',':','-.'}

数据类型:char|细绳|cell

内核密度图线的宽度,指定为逗号分隔对'行宽'以及非负标量值的非负标量值或向量。指定的值是以点测量的内核密度图线的大小。默认大小为0.5点。使用向量为每个组指定不同的线宽度。当组总数大于指定值的数量时,scatterhistcycles through the specified values.

例子:'行宽',[0.5,1,2]

数据类型:single|双倍的

Marker color for each scatter plot group, specified as the comma-separated pair consisting of'颜色'and a character vector or string scalar of color names, or a three-column matrix of RGB values in the range [0,1]. If you specify colors using a matrix, then each row of the matrix is an RGB triplet that represents a group. The three columns of the matrix represent the R value, G value, and B value, respectively. When the total number of groups exceeds the number of specified colors,scatterhistcycles through the specified colors.

This table lists the predefined colors and their equivalent RGB triplet values.

Option 描述 等效的RGB三胞胎
'red'or'r' Red [1 0 0]
'green'or'G' 绿色的 [0 1 0]
'蓝色的'or'b' Blue [0 0 1]
'黄色'or'y' Yellow [1 1 0]
'品红'or'M' Magenta [1 0 1]
'cyan'or'C' 青色 [0 1 1]
'white'or'w' White [1 1 1]
'black'or'K' Black [0 0 0]

例子:'颜色','kcm'

例子:'颜色',[.5,0,1;0,.5,.5]

数据类型:single|双倍的|char|细绳

Marker symbol for each scatter plot group, specified as the comma-separated pair consisting of'Marker'and a character vector or string scalar of one or more valid marker symbols. Seeplot对于有效的符号。默认值为'o', a circle. When the total number of groups exceeds the number of specified symbols,scatterhist循环通过指定的符号。

例子:“标记”,'+do'

数据类型:char|细绳

每个散点图组的标记大小,指定为逗号分隔对'MarkerSize'以及非负标量值或非负标量值的向量,以点为点。当组总数超过指定值的数量时scatterhistcycles through the specified values.

例子:'MarkerSize',10

数据类型:single|双倍的

输出参数

collapse all

Axes handles for the three plots, returned as a vector. The vector contains the handles for the scatter plot, the histogram along the horizontal axis, and the histogram along the vertical axis, respectively.

Alternative Functionality

Alternatively, you can create aScatterHistogramChart对象通过使用分散组织图function.

  • Explore the data interactively in the object by panning, zooming, and using data tips. Unlike thescatterhistfunction,分散组织图根据当前散点图限制中的数据更新边缘直方图。

  • Control the appearance and behavior of the scatter histogram chart by changing theScatterHistogramChart Properties.

Introduced in R2007a