2011-12-09 9 views
7

matplotlib를 사용하여 플롯하려고하는 점이 많습니다. 각 점 (a, b)에 대해 [0, b]에 Y에 대해 X = a 선을 그립니다. 어떤 생각을 어떻게 할 것인가?x 축에서 점으로 선 그리기

답변

9

두 개의 끝점을 사용하여 각 선을 그립니다. [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

stem 음모에게 사용을

는 적어도 성가신 솔루션은 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

을 사용