2017-01-14 8 views
0

は、それらが期待通りに表示されます。画像上の線が座標と一致しません。私は、画像上の点を順次プロットのpython

import numpy as np 
import matplotlib.pyplot as plt 
#display in a jupyter notebook 
%matplotlib inline 
#make and display data 
image = np.full((50,60,), 0, dtype = 'float32') 
image[10:20, 10:20] = .5 
image[10,20, 30:40] = .5 
plt.plot(15,15, 'y*') 
plt.plot(35,15, 'b*') 
plt.imshow(image) 

points plotted on image

しかし、私はこれらの2点間のラインをプロットしようとすると、別の軸規則を使用するように見えます:

plt.plot([15,15], [35,15], 'y-') 
plt.imshow(image) 

weird plotting

私のポイントの配列を指定した場合ラインは、それが正常に動作します:

line_x = np.array(range(15,35)) 
line_y = np.repeat(15, 20) 
plt.plot(line_x, line_y, 'y-') 
plt.imshow(image) 

line points specified

私はmatplotlibのは、これらのプロットのタスクに異なる軸規則を使用していると思いますが、プロットする際に、シーケンシャルポイントをプロットではなく、一方で、私はこれがうまくいく理由として混乱しています2点間の接続線?

コンテキスト:私はskimage.measure.profile_lineを使用してlinescanを実行していますhttp://scikit-image.org/docs/dev/api/skimage.measure.html。この機能を使ってlinescanの開始と終了を指定しますが、私の画像が私のラインスキャンのどこにあるかを視覚的に実演したいと思います。

答えて

1

matplotlibのは常にx水平座標であり、y座標垂直である

plt.plot(x,y, ...) 

、同じ規則を使用します。これは、点の線をプロットするかどうかに関係なく行われます。最初のポイントのx座標

plt.plot(15,15, 'y*') 
plt.plot(35,15, 'b*') 

15で呼び出すと、第二の点のx座標

35あります。 plt.plot([15,15], [35,15], 'y-')を呼び出すと、2つの点の両方のx座標が15になります。
したがって、あなたがそれらをプロットすることができ二点

x1 = 15; y1 = 15 
x2 = 35; y2 = 15 

を持ついずれか

plt.plot(x1,y1, 'y*') 
plt.plot(x2,y2, 'b*') 

または

plt.plot([x1,x2], [y1,y2], 'y-') 
+0

によってはそれを片付けてくれてありがとう! – Nick

関連する問題