【发布时间】:2020-07-09 23:11:46
【问题描述】:
我试图根据特定属性为我的网络节点着色,但是函数 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')
【问题讨论】:
-
您已将属性
'r'添加到您的数据框nodes而不是您的图表G_nx。