ベースコードhereから、Figureをプロットし、Figureの上と下の両方にx軸のラベルを付ける関数を作成しました。左右のy軸ラベル。MATLAB:プロットの各辺にxとyのラベルを付ける問題
:私の問題は、私はラベルが上書きされ、何らかの理由で、y軸のラベルを示し、 最初の実行などの奇妙な方法で上書きゲットするコードを複数回実行する必要があり、その都度ということですセカンドラン:
次はMWEです:
% sample data, plot
x=[1:168];
y=x;
plot(x, y, 'r', 'LineWidth', 1);
set(gca, 'XTick', [], 'YTick', []);
% set left yaxis label
ylabel(directions{1,1},'Rotation',-360);
% Adjust position - this seems to be what's causing the issue!
ylabelh = get(gca,'YLabel');
rpos = get(ylabelh,'Position');
set(ylabelh,'Position',rpos + [1.5*rpos(1) 0 0])
% do stuff... as per link above
axesPosition = get(gca,'Position');
hNewAxes = axes('Position',axesPosition,... %# Place a new axes on top...
'Color','none',... %# ... with no background color
'YAxisLocation','right',... %# ... located on the right
'XTick',[],'YTick',[],... %# ... with no x tick marks
'Box','off');
ylabel(hNewAxes,directions{2,1},'Rotation',-360); % yaxis label right
% Adjust position
ylabelh = get(gca,'YLabel');
Lpos = get(ylabelh,'Position');
set(gca,'YTick',[]);
set(ylabelh,'Position',Lpos+ [+Lpos(1)*0.02 0.05 0])
% -- And repeat for x axis -- %
% x axis labels
xlabel(directions{3,1},'Rotation',-360); % xaxis label bottom
% Adjust position
xlabelh = get(gca,'XLabel');
xlabpos = get(xlabelh,'Position');
set(gca,'XTick',[]);
rpos = get(xlabelh,'Position');
% do stuff ... as above
axesPosition = get(gca,'Position');
hNewAxes = axes('Position',axesPosition,... %# Place a new axes on top...
'Color','none',... %# ... with no background color
'XAxisLocation','top',... %# ... located on the right
'XTick',[],'YTick',[], ... %# ... with no x tick marks
'Box','off');
% xaxis label top
xlabel(hNewAxes,directions{4,1},'Rotation',-360);
奇妙なことに、スクリプトとしてコードを実行すると(ラベルは上書きされますが、y軸のラベルに問題はありません)、デバッグモードで複数回実行すると私がそれを使用している現在の主な方法)、私は上記の人工物を見る。