2011-12-09 16 views
7

matplotlibを使ってプロットしようとしている点がたくさんあります。各点(a、b)について、[0、b]にYの線X = aを描きたい。どのようにこれを行うにはどのようなアイデア?x軸から点に線を引く

答えて

9

2つのエンドポイントを使用して各行を描画します。 [0、b]のYの垂直線X = aは、端点(x​​、y)=(a、0)と(a、b)を持ちます。だから、 :

# make up some sample (a,b): format might be different to yours but you get the point. 
import matplotlib.pyplot as plt 
points = [ (1.,2.3), (2.,4.), (3.5,6.) ] # (a1,b1), (a2,b2), ... 

plt.hold(True) 
plt.xlim(0,4) # set up the plot limits 

for pt in points: 
    # plot (x,y) pairs. 
    # vertical line: 2 x,y pairs: (a,0) and (a,b) 
    plt.plot([pt[0],pt[0]], [0,pt[1]]) 

plt.show() 

は、次のようなものを与える: drawing vertical lines

1

少なくとも面倒なソリューションがmatplotlib.pyplot.stem

import matplotlib.pyplot as plt 
x = [1. , 2., 3.5] 
y = [2.3, 4., 6.] 
plt.xlim(0,4) 
plt.stem(x,y) 
plt.show() 

enter image description here

を採用stemプロット

を使用します

関連する問題