2
我很困惑如何調整大小在matlab中使用兩個座標軸的圖。我在結果中發現行爲不一致,具體取決於我是在調試器中單步執行圖形生成代碼(正常工作),還是一次全部運行。在非交互模式下調整Matlab座標軸意外行爲
例如,在下面的函數,我連接我的兩個軸的位置屬性:
- 如果我把最後一行斷點,單步執行它,第一軸的位置因爲它應該是
- ,如果我跑,一次就全部,它不會改變,並得到與第二軸
,這是什麼原因錯位自動改變?
我正在使用2015B,如果這件事。
function graph_test
% set up a horizontal bar plot with a scattre plot on a secondary x-axis
% at the top
barh(1:10)
ax1 = gca;
set(ax1,'Box','off');
ax2 = axes('XAxisLocation','top','Color','none','Position', ax1.Position);
linkaxes([ax1 ax2],'y');
linkprop([ax1 ax2],'Position');
set(ax2,'Ytick',[]);
hold on;
scatter(ax2,[1:-.1:.1],[1:10]);
xlabel(ax1,'bottom axis');
xlabel(ax2,'top axis');
% set title
% we need to set this on second axis so that it does
% not overlap with axis legend
% the secondary axis is not auto resized as per matlab docs
title(ax2,'My graph');
% resize ax2 manually
ax2.OuterPosition(4) = 1-ax2.OuterPosition(1);
end