[转载]matlab的scatterhist 用法--将散点图和直方图结合!

标签:
转载 |
分类: MATLAB |
scatter用来画散点图,而hist系列的函数是用来画直方图,具体应用可以在官网上找到。
要想把散点图和直方图结合起来,可以用scatterhist函数。
具体用法见官网:http://www.mathworks.cn/help/toolbox/stats/scatterhist.html
其中,用法如下:
scatterhist(x,y)
h = scatterhist(...)
scatterhist(...,'param1',val1,'param2',val2,...)
注意:x和y必须所含元素个数相同,即维数相同
参数可以有以下三种:
-
'NBins' — A scalar or a two-element vector specifying the number of bins for the X and Y histograms. The default is to compute the number of bins using Scott's rule based on the sample standard deviation.
-
'Location' — A string controlling the location of the marginal histograms within the figure. 'SouthWest' (the default) plots the histograms below and to the left of the scatterplot, 'SouthEast' plots them below and to the right, 'NorthEast' above and to the right, and 'NorthWest' above and to the left.
-
'Direction' — A string controlling the directation of the marginal histograms in the figure. 'in' (the default) plots the histograms with bars directed in towards the scatterplot, 'out' plots the histograms with bars directed out away from the scatterplot.
NBins就是指直方图的单位间隔,默认间隔是标准差
Location是指直方图位于散点图的那个位置,默认是西南,意思是在左侧和下方。
Direction是指直方图的朝向,默认是“in”即朝向散点图,而out是朝外。
如下图几个例子:
Example 1
Independent normal and lognormal random samples:
x = randn(1000,1); y = exp(.5*randn(1000,1)); scatterhist(x,y)
http://www.mathworks.cn/help/toolbox/stats/scatterhist1.png用法--将散点图和直方图结合!" />
Example 2
Marginal uniform samples that are not independent:
u = copularnd('Gaussian',.8,1000); scatterhist(u(:,1),u(:,2),'Direction','out')
http://www.mathworks.cn/help/toolbox/stats/scatterhist2.gif用法--将散点图和直方图结合!" />
Example 3
Mixed discrete and continuous data:
load('carsmall'); scatterhist(Weight,Cylinders,'NBins',[10 3],'Direction','out')
http://www.mathworks.cn/help/toolbox/stats/scatterhist3.gif用法--将散点图和直方图结合!" />