0

これが私のコードです

clear all;clc
x = linspace(0, 10, 100);

axes('Position', [.075,.075,.9,.2], ...
     'XColor',   'k', ...
     'YColor',   [0 0 0]);
fill(x, circshift(sin(x), 50), 'red', 'EdgeColor','None');
ylabel('Fancy Sine', 'FontSize', 11);

% Adding this the upper vanishes and the y axes is on left not right side
axes('Position',      [.075,.075,.9,.2], ...
     'XColor',        'k', ...
     'YAxisLocation', 'Right', ...
     'Color',         'none');
plot(x, x, 'Color', [.2 .4 .8]);
ylabel('Line Graph', 'FontSize', 11);

xlabel('X', 'FontSize', 11);

単軸は正常に動作します

ここに画像の説明を入力

しかし、2番目の軸を追加したい場合、最初の軸は消え、新しい軸は右側ではなく左側にあります..

ここに画像の説明を入力

ただし、両方のプロットが 1 つの軸にあり、2 番目の y 軸が右側にある必要があります。

これを達成する方法は?

4

1 に答える 1

2

plot軸のプロパティをデフォルトに自動的に設定します。holdこれを停止するか、呼び出し後に軸のプロパティを指定するために使用しますplot

前者の例:

clear all;clc
x = linspace(0, 10, 100);

ax1 = axes('Position', [.075,.075,.9,.2], ...
     'XColor',   'k', ...
     'YColor',   [0 0 0]);
p1 = fill(x, circshift(sin(x), 50), 'red', 'EdgeColor','None','Parent',ax1);
ylabel('Fancy Sine', 'FontSize', 11);

% Adding this the upper vanishes and the y axes is on left not right side
ax2 = axes('Position',      [.075,.075,.9,.2], ...
     'XColor',        'k', ...
     'YAxisLocation', 'Right', ...
     'Color',         'none');
hold on
p2 = plot(ax2,x, x, 'Color', [.2 .4 .8]);
hold off
ylabel('Line Graph', 'FontSize', 11);
xlabel('X', 'FontSize', 11);

Edit1: 呼び出しでこれを行う必要がない理由は、Axes にオブジェクトをfill作成し、コマンドを呼び出さないためです。patchplot

于 2014-08-21T14:47:35.120 に答える