2017-12-18 15 views
1

"How to insert two X axis in a Matlab plot"という質問に答えて、2つのx軸を重ねてグラフを作成しました。2つの積み重ねられたx軸の間の垂直線

私は今、特定のx値で2つのx軸の間に垂直線を作成しようとしています。たとえば、リンクされた質問のような図があるとします。 2つのx軸間の値をx = 2 m/sにして縦線を描くにはどうすればよいですか?

Here is an image of what I am looking for. The red line is what I am trying to draw in MATLAB. The two x-axes both have the same scale.

+0

あなたはより詳細なだろうか?あなたはx軸に異なる縮尺を与えます。あなたのスケールは同じですか?あなたはあなたが望むものの例を添付するだけですか? (ペイントでこの線を描くだけです) – zlon

+0

これは、Matlabがまだ正しいツールであるかどうかを本当に考えるべきポイントです。 Inkscape、Illustrator、tikz&coはあなたに多くの時間を節約するはずです。 – thewaywewalk

+0

私は、非常に大きなデータセットとたくさんのグラフのX軸上の特定の点にこれらの線を作成しようとしています。 MATLABではそれが不可能だと思うなら、私は他のプログラムを見ます。しかし、MATLABに最初にある方法があるかどうかを見たいと思っていました。 –

答えて

0

これはなんとかますが、注意が必要です。 annotationを使用しましたが、FigureユニットからAxesユニットにマップする必要があります。ここに行く:

% experimental data 
M(:,1) = [ 0, 1, 2, 3, 4, 5]; 
M(:,3) = [12, 10, 15, 12, 11, 13]; 

% get bounds 
xmaxa = max(M(:,1))*3.6; % km/h 
xmaxb = max(M(:,1));  % m/s 

figure; 

% axis for m/s 
b=axes('Position',[.1 .1 .8 eps]); 
set(b,'Units','normalized'); 
set(b,'Color','none'); 

% axis for km/h with stem-plot 
a=axes('Position',[.1 .2 .8 .7]); 
set(a,'Units','normalized'); 
stem(a,M(:,1).*3.6, M(:,3)); 

% set limits and labels 
set(a,'xlim',[0 xmaxa]); 
set(b,'xlim',[0 xmaxb]); 
xlabel(a,'Speed (km/h)') 
xlabel(b,'Speed (m/s)') 
ylabel(a,'Samples'); 
title(a,'Double x-axis plot'); 

% this where the trick happens 
pos = get(b, 'Position') ; 
x_normalized = @(x0) (x0 - min(b.XLim))/diff(b.XLim) * pos(3) + pos(1); 
xl = [x_normalized(2) x_normalized(2)]; % because you wanted x=2 m/s 
yl = [0.1 0.2]; 
annotation('line',xl,yl,'Color',[1 0 0]) 

enter image description here

関連する問題