我有一个图表,每个标签都是它的重量。我想垂直显示其标签。我该怎么做?
我的代码是:
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
import pylab
G = nx.DiGraph()
G.add_node('A',pos=(0,100))
G.add_node('B',pos=(2,50))
G.add_node('C',pos=(-2,50))
G.add_node('D',pos=(0,40))
G.add_node('E',pos=(1,10))
G.add_node('F',pos=(-1,10))
G.add_node('G',pos=(0,-50))
G.add_edges_from([('A', 'B')], weight=1)
G.add_edges_from([('F','G')], weight=1)
G.add_edges_from([('C','F')], weight=2)
G.add_edges_from([('A','D')], weight=3)
G.add_edges_from([('D','F'),('E','G')], weight=4)
G.add_edges_from([('A','C')], weight=5)
G.add_edges_from([('B','E')], weight=6)
G.add_edges_from([('D','G')], weight=8)
G.add_edges_from([('B','D')], weight=9)
edge_labels=dict([((u,v,),d['weight'])
for u,v,d in G.edges(data=True)])
pos=nx.get_node_attributes(G,'pos')
nx.draw_networkx_edge_labels(G,pos,edge_labels=edge_labels, rotation='vertical')
nx.draw(G,pos, node_color='lightgrey',with_labels=True, node_size=1000, rotation='vertical')
pylab.show()
plt.savefig('graph.png')
我用过
rotation='vertical
但它并没有真正起作用。