0
所以我有以下函數來繪製一個問題即時通訊工作。它基本上是一個關鍵的節點檢測問題或阻塞。我有一些值x,並決定攻擊節點z。基本上我想用正在處理/攻擊的活動和不活動節點和節點爲我的圖表着色。這是我到目前爲止。圖例爲networkx繪圖功能
DEF draw_solution(克,zsolution,xsolution,T,XMIN = 0,文件名= '檢驗.pdf'):
# draw solution
pos = {n: ndata['coord'] for n,ndata in g.nodes_iter(data=True)}
ncolour=[]
for n,ndata in g.nodes_iter(data=True):
if ndata['fuel_load'] < xmin:
ncolour.append('gold')
else:
ncolour.append('yellowgreen')
pp = PdfPages(filename)
fig = plt.figure(figsize=(11.7,8.3))
fig.suptitle('full graph and initial fuel load')
plt.axis('off')
nx.draw_networkx(g, pos, font_size=9, node_color=ncolour)
fig.savefig(pp, format='pdf')
fig.clf()
for t in range(T):
g_copy = g.copy()
#node colour
ncolour=[]
for i in g.nodes_iter():
if zsolution[i,t] > 0.99:
ncolour.append('lightcoral')
#g_copy.remove_edges_from(g.edges(i))
elif xsolution[i,t] < xmin:
ncolour.append('gold')
g_copy.remove_edges_from(g.edges(i))
else:
ncolour.append('yellowgreen')
plt.axis('off')
fig.suptitle('t={}, before treatment'.format(t))
nx.draw_networkx(g_copy, pos, font_size=9, node_color=ncolour, label=ncolour)
fig.savefig(pp, format='pdf')
fig.clf()
g_copy = g.copy()
#node colour
ncolour=[]
for i in g.nodes_iter():
if zsolution[i,t] > 0.99:
ncolour.append('lightcoral')
g_copy.remove_edges_from(g.edges(i))
elif xsolution[i,t] < xmin:
ncolour.append('gold')
g_copy.remove_edges_from(g.edges(i))
else:
ncolour.append('yellowgreen')
plt.axis('off')
fig.suptitle('t={}, after treatment'.format(t))
nx.draw_networkx(g_copy, pos, font_size=9, node_color=ncolour, label=ncolour)
fig.savefig(pp, format='pdf')
fig.clf()
pp.close()
fig.clf()
出於某種原因,我不能得到圖例正確?
請幫忙!謝謝!
你想發生什麼事情沒有發生? - 「傳說」是什麼意思? – Joel
我想要一個對應於顏色的圖例。所以我想要像 lightcoral - 攻擊 黃金 - 活躍 yellowgreen - 無效 –