【发布时间】:2021-09-27 07:48:26
【问题描述】:
几天前我开始使用networkx lib。我想知道是否可以更改图表上边缘的长度? 我绘制了一个图表,但节点彼此非常接近,因此节点名称重叠(请查看下图)。 这是我的代码:
import networkx as nx
import matplotlib.pyplot as plt
# Defining graph .Graph() and .DiGraph()
analysis_graph = nx.DiGraph()
# Adding relations to the graph
analysis_graph.add_edges_from(relation_list)
# extracting nodes from relations - Unique node entities
node_list = list(nx.nodes(analysis_graph))
print(type(node_list))
# Creating sizes for each node (degree - number of relations from each node)
dict_of_node_sizes = dict(analysis_graph.degree) # for getting node sizes
print(dict_of_node_sizes)
# Same graph each time
my_pos = nx.spring_layout(analysis_graph.to_undirected(), seed = 0)
#.to_undirected() -> Making shape of directed graph like undirected graph
# Printing graph info
print(nx.info(analysis_graph))
# Printing graph
plt.figure(figsize=(25,17))
nx.draw(analysis_graph,
pos = my_pos,
with_labels = True,
arrowsize=10,
font_size=10,
node_size=[(v+1) * 120 for v in dict_of_node_sizes.values()])
这是我的图表:
你知道我怎样才能修正图表的外观,使点头清晰可见吗? 我应该制作更长的边缘(如何)还是应该更改字体或其他什么?
【问题讨论】:
-
analysis_graph.add_edge('A', 'B', length = 1)
-
analysis_graph.add_edges_from([(1, 2), (2, 3)], weight=3)
-
它不起作用,它不会改变
-
我将列表传递给'analysis_graph.add_edges_from(relation_list)',我尝试添加length = 1,length = 10,但结果是一样的