I need to plot a bunch of unit vectors and histograms corresponding to both axes (as a simple way to visualize clustering).
This is what I want: https://i.stack.imgur.com/hIeev.jpg.
- The axes for the histogram are aligned with the unit vector plot.
This is what I am getting: https://i.stack.imgur.com/J8HA5.jpg
- The axes are misaligned
=
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');