plotyyで描画し​たFigureにy軸​をもう1つ追加したい​のですが、どうすれば​よいですか?

18 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2013 年 10 月 25 日
回答済み: MathWorks Support Team 2013 年 10 月 25 日
plotyyで描画したFigureにy軸をもう1つ追加したいのですが、どうすればよいですか?

採用された回答

MathWorks Support Team
MathWorks Support Team 2013 年 10 月 25 日
2つのAxes(y軸目盛り表示用のAxesとデータ表示用のAxes)を追加する方法があります。 y軸目盛り表示用のAxesは、plotyyで作成したAxesに重ならないようにずらして配置し、x軸の色をFigureの背景と同色にすることで、y軸の目盛りのみ表示します。
データ表示用のAxesは、データを描画した後で非表示に設定し、データ部分のみ表示します。
【実行例】
% 描画用データ作成
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
y3 = sin(x)+x;
% Axesをずらして配置し、x軸の色をFigureの背景と同色に変更
ax1 = axes;
posi = get(ax1,'Position');
bc = get(gcf,'Color');
newposi = [posi(1)-0.07,posi(2),posi(3)-0.07,posi(4)];
set(ax1,'Position',newposi,'Color','None','Box','Off',...
'XColor',bc,'YColor','r','XTick',[],'XTickLabel',[])
% plotyyでデータを描画
ax2 = axes;
plotyy(x,y1,x,y2,'plot');
% Axesを作成して3つ目のデータを描画し、Axesを非表示に設定
ax4 = axes;
plot(x,y3,'r')
set(ax4,'Visible','Off')
yl = get(ax4,'YLim');
set(ax1,'YLim',yl)

その他の回答 (0 件)

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!