1

Figure に 2 番目の x 軸を追加しようとしています。動作しているように見えますが、2 番目の軸ラベルが Figure の半分外側に表示されています。つまり、「2nd Axis」の下半分しか表示されていません。問題を示す小さな例を次に示します。

close all;

ax1 = gca;
set(ax1,'XColor','r','YColor','r')
xlabel(ax1, '1st Axis');


data=rand(10,2);
line(data(:,1), data(:,2), 'Color', 'r');

ax2 = axes('Position',get(ax1,'Position'),...
           'XAxisLocation','top',...
           'YAxisLocation','right',...
           'Color','none',... % necessary, or the axes do not appear
           'XColor','k','YColor','k');
xlabel(ax2, '2nd Axis');

data=rand(10,2);
line(data(:,1), data(:,2), 'Color', 'k','Parent', ax2);

「上」以外に軸ラベルを配置するより良い方法はありますか? または、「図の中にすべてを収める」と言う方法はありますか?

4

2 に答える 2

0

xLabel を最適な位置に設定する方法があれば、legend('','Location','best') を信用しないので、信用しません。

私の考えでは2つの方法:

set(get(ax2,'XLabel'),'Position',get(xlabh,'Position) - [0 .2 0])

また

ax1 = axes('XColor','r','YColor','r','Position',[0.1 0.1 0.9 0.7]);
于 2013-05-02T18:34:03.387 に答える
0

このコマンドが役に立ちます:追加情報については、この Web サイト
'ActivePositionProperty','OuterPosition'
を 参照してください。 次のコマンドを使用して、上軸を調整する必要があります。

ax2 = axes('Position',get(ax1,'Position'),...
       'XAxisLocation','top',...
       'YAxisLocation','right',...
       'Color','none',... % necessary, or the axes do not appear
       'XColor','k','YColor','k','ActivePositionProperty','OuterPosition');

プロットを組み立てる順序が重要でない場合は、赤軸が他の軸に合うように反転します。

close all;

ax2 = axes('XAxisLocation','top',...
           'YAxisLocation','right',...
           'XColor','k','YColor','k','ActivePositionProperty','OuterPosition');
xlabel(ax2, '2nd Axis');

data=rand(10,2);
line(data(:,1), data(:,2), 'Color', 'k','Parent', ax2);

ax1 = axes('Position',get(ax2,'Position'),...
           'Color','none',... % necessary, or you do not see the second graph
           'XColor','r','YColor','r');
xlabel(ax1, '1st Axis');

data=rand(10,2);
line(data(:,1), data(:,2), 'Color', 'r');
于 2013-05-02T18:28:03.143 に答える