我试图根据特定属性为网络的节点着色,但是功能ox.plot.get_node_colors_by_attr()
不起作用。
错误是:ValueError: There are no attribute values.
以下是代码:
import networkx as nx
import numpy as np
import osmnx as ox
ox.config(use_cache=True, log_console=True)
city = 'Portugal, Lisbon'
G = ox.graph_from_place(city, network_type='drive', simplify=True)
G_nx = nx.relabel.convert_node_labels_to_integers(G)
nodes, edges = ox.graph_to_gdfs(G_nx, nodes=True, edges=True)
r_total = np.random.random(len(G_nx))
nodes['r'] = nodes.index.map(lambda x: r_total[x])
nodes.head()
nc = ox.plot.get_node_colors_by_attr(G_nx, attr='r')
答案 0 :(得分:1)
如果替换行
headerLayout
使用
match_parent
您的代码应该可以工作(set_node_attributes
的文档)-即使我不明白为什么您会以这种复杂的方式分配随机值,但我想这只是一个最小的,可重复的示例。 / p>