2013-03-21 5 views
11

curveSeq이 보유한 Y 값의 주어진 시퀀스에서 그래프를 만듭니다. (는 X 값은 자동으로 열거 : 0,1,2 ...)networkx를 사용하는 노드 레이블

curveSeq = [10,20,30]를 들어, 내 그래프는 점을 포함합니다 :

<0,10>, <1,20>, <2,30>. 

나는 같은에 일련의 그래프를 그리기 해요을 nx.Graph을 사용하면 모든 사진을 한 장의 사진에 표시 할 수 있습니다.

내 문제는 다음과 같습니다

  • 각 노드는 자신의 위치를 ​​제공합니다. 즉 위치가 <0,10> 인 노드는 해당 레이블을 표시하며이를 제거하는 방법을 알지 못합니다.
  • 레이블을 추가 할 특정 노드가 있지만 방법을 모르겠습니다. 예

시퀀스를 들어

[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1] 

수신 그래프이다

graph

코드는 :

for point in curveSeq: 
       cur_point = point 
       #assert len(cur_point) == 2 
       if prev_point is not None: 
        # Calculate the distance between the nodes with the Pythagorean 
        # theorem 
        b = cur_point[1] - prev_point[1] 
        c = cur_point[0] - prev_point[0] 
        a = math.sqrt(b ** 2 + c ** 2) 
        G.add_edge(cur_point, prev_point, weight=a) 
       G.add_node(cur_point) 
       pos[cur_point] = cur_point 
       prev_point = cur_point 
      #key: 
      G.add_node((curve+1,-1)) 
      pos[(curve+1,-1)] = (curve+1,-1) 

      nx.draw(G, pos=pos, node_color = colors[curve],node_size=80) 
      nx.draw_networkx_edges(G,pos=pos,alpha=0.5,width=8,edge_color=colors[curve]) 

    plt.savefig(currIteration+'.png') 

답변

19

당신은 with_labels=False를 추가 할 드러내지 않는 키워드 라벨의 날개는 networkx.draw(), 예 :

networkx.draw(G, pos=pos, node_color=colors[curve], 
    node_size=80, with_labels=False) 

그런 다음 라벨을 라벨에 대한 사전 매핑 노드 ID입니다

networkx.draw_networkx_labels(G,pos, labels) 

과 특정 레이블을 그립니다.

링크가 깨진 http://networkx.github.com/documentation/latest/examples/drawing/labels_and_colors.html

+0

이 예에서 살펴 보자. 대신 https://networkx.github.io/documentation/networkx-1.10/examples/drawing/labels_and_colors.html을 사용하십시오. – blacksite

관련 문제