2013-10-24 41 views
8

私は、y軸上で異なるスケーリングで 'contourf'によって生成されたディスプレイの上に 'plot'で作成されたxyタイムシリーズをオーバーレイする方法を探しています。Matlabプロットで2軸をオーバーレイする

2つのxyプロットの場合にこれを行う典型的な方法は、 'plot'以外の関数( 'loglog'など)によって駆動される組み込み関数 'plotyy' )で、入力引数が同じ(x、y)のままである限りです。しかし、私の場合、contourfは3つの入力引数を必要とするので、 'plotyy'は適用できないようです。ここで私がやりたいものを記述したいくつかのサンプルコードは、次のとおりです。理想的

x1 = 1:1:50; 
y1 = 1:1:10; 
temp_data = rand(10,50); 
y2 = rand(50,1)*20; 
figure; hold on; 
contourf(x1,y1,temp_data); 
colormap('gray'); 
plot(x1,y2,'r-'); 

、私は右側に表示され、独自のy軸を持つように時系列(X1、Y2)を希望し、同じにスケーリングしますcontourfプロットとしての垂直エクステント。

お時間をいただきありがとうございます。

+0

:http://stackoverflow.com/questions/11531762/matlab-multiple-x-axisここ

は出力例です(私は読みやすさのためにフォントサイズを増加しました) -one-below-another – Dan

+0

+1の再現性のあるコードを投稿する –

+0

[この投稿](http://stackoverflow.com/questions/1719048/plotting-4-curves-in-a-single-plot-with-3-y -axes)が必要なものかもしれません。 – chappjc

答えて

6

私はこれを行うための "クリーンな"方法はないと思っていますが、お互いの上に2つの軸を重ねることで偽装することができます。

x1 = 1:1:50; 
y1 = 1:1:10; 
temp_data = rand(10,50); 
y2 = rand(50,1)*20; 
figure; 
contourf(x1, y1, temp_data); 
colormap('gray'); 
h_ax = gca; 
h_ax_line = axes('position', get(h_ax, 'position')); % Create a new axes in the same position as the first one, overlaid on top 
plot(x1,y2,'r-'); 
set(h_ax_line, 'YAxisLocation', 'right', 'xlim', get(h_ax, 'xlim'), 'color', 'none'); % Put the new axes' y labels on the right, set the x limits the same as the original axes', and make the background transparent 
ylabel(h_ax, 'Contour y-values'); 
ylabel(h_ax_line, 'Line y-values'); 

は実際には、この「プロット・オーバーレイは、」ほとんど間違いなくplotyy関数は内部的に何をするかです。あなたはこの質問に答えを見つけるかもしれない overlaid axes

関連する問題