11
我使用curveSeq
保存的給定Y值序列創建圖表。 (X值自動列舉:0,1,2 ...)使用網絡的節點標籤x
即對於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]
所接收的曲線圖是:
的代碼是:
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')
該鏈接已損壞。改爲使用它:https://networkx.github.io/documentation/networkx-1.10/examples/drawing/labels_and_colors.html – blacksite 2016-10-05 13:46:00