2015-02-01 5 views
0

나는 pyplot을 처음 접하고 내가 잘못하고있는 것이 궁금합니다.내 pyplot에 줄이 표시되지 않는 이유는 무엇입니까?

I 임의의 선 세그먼트의 일련의 음모 싶습니다 점하지만 사이의 라인이 있어야한다,

여기
import matplotlib.pyplot as plt 

def testPlot(): 
    minx = miny = -1 
    maxx = maxy = 30 
    # some points randomly generated 
    points = [((10, 21), (19, 22)), ((11, 9), (22, 27)), ((9, 13), (5, 9)), ((18, 4), (2, 21)), ((25, 27 
    for pair in points: 
    print pair 
    for point in pair: #plot each point with a small dot 
     x = point[0] 
     y = point[1] 
     plt.plot(x,y,'bo') 
    # draw a line between the pairs of points 
    plt.plot(pair[0][0],pair[0][1],pair[1][0],pair[1][1],color='r',linewidth=2) 
    plt.axis([minx,maxx,miny,maxy]) 
    plt.show() 

가 나는 것을 실행 한 후 무엇을 얻을 수 있습니다 : 여기

몇 가지 예제 코드입니다 줄 이니?

... 
plt.plot(pair[0][0],pair[0][1],pair[1][0],pair[1][1],color='r',linewidth=2) 
... 

당신은 어떤 사실해야, x,y,x1,y1에 참조를 그릴려고 :

plotted points but no lines

((10, 21), (19, 22)) 
((11, 9), (22, 27)) 
((9, 13), (5, 9)) 
((18, 4), (2, 21)) 
((25, 27), (11, 13)) 
이이 문제의 라인 단서

답변

2

주셔서 감사합니다 ((x, x1), (y, y1))이됩니다. 이 잘 작동 보인다 수정 :

def testPlot(): 
    minx = miny = -1 
    maxx = maxy = 30 
    # some points randomly generated 
    points = [((10, 21), (19, 22)), ((11, 9), (22, 27)), ((9, 13), (5, 9)), ((18, 4), (2, 21)), ((25, 27), (11, 13))] 
    for pair in points: 
    print pair 
    for point in pair: #plot each point with a small dot 
     x = point[0] 
     y = point[1] 
     plt.plot(x,y,'bo') 
    # change this line to ((x, x1), (y, y1)) 
    plt.plot((pair[0][0],pair[1][0]),(pair[0][1],pair[1][1]), color='r',linewidth=2) 
    plt.axis([minx,maxx,miny,maxy]) 
    plt.show() 

결과 :

enter image description here

+0

오, 멋진, 감사합니다! – slashdottir

+0

@slashdottir, 문제가 아니므로 도움이 됨 :) – Anzel

관련 문제