我需要绘制一组对应于两个轴的单位向量和直方图(作为可视化聚类的简单方法)。
这就是我想要的:http: //imgur.com/SBO34t8。
- 直方图的轴与单位矢量图对齐。
这就是我得到的:http: //imgur.com/Q4hcPOy
- 轴未对齐
=
x = randn(100,1);
y = randn(100,1);
data = [x y];
normData = rowfun(@(n) n./norm(n,2),table(data));
xData = normData{:,:}(:,1);
yData = normData{:,:}(:,2);
blankFigure([-1 1 -1 1]); hold on;
cellfun(@(x,y) plot([0 x], [0 y],'LineWidth',3),num2cell(xData),num2cell(yData))
ax1 = gca;
ax1Pos = get(ax1,'Position');
ax2Pos = ax1Pos;
ax2Pos(2) = ax1Pos(2)-.05;
ax2 = axes('Position',ax2Pos);
edges = [-1:.1:1];
histogram(xData,edges,'Normalization','pdf','Orientation','vertical');
set(ax2,'XLim',get(ax1,'XLim'));
set(ax2,'YLim',[0 8]);
set(ax2,'Visible','off');
ax3Pos = ax1Pos;
ax3Pos(1) = ax1Pos(1)-.05;
ax3 = axes('Position',ax3Pos);
histogram(yData,edges,'Normalization','pdf','Orientation','horizontal')
set(ax3,'YLim',get(ax1,'YLim'));
set(ax3,'XLim',[0 8]);
set(ax3,'Visible','off')
set(ax1,'Visible','on');