【问题标题】:Assign a color to a specific edge in osmnx graph based on a given u,v node values根据给定的 u,v 节点值为 osmnx 图中的特定边分配颜色
【发布时间】:2018-12-29 00:54:49
【问题描述】:

我正在绘制一个 osmnx 图:虽然我可以控制节点颜色,但我无法控制边缘颜色。

我的目标是仅将蓝色分配给由 u_node = 4515988732 和 v_node=2021402216 定义的边缘。我试过了:

for u,v,k in G.edges(keys=True, data=False):
    if (u==4515988732 and v==2021402216):
       ev='b'

但是当我用以下方法绘制它们时,所有边缘都被绘制为蓝色:

fig, ax = ox.plot_graph(G, fig_height=7, node_color=nc, 
node_size=10, node_alpha=0.8, node_zorder=2,
edge_color=ev, edge_linewidth=1)

我也试过了:

ev=[(u,v,'b') for u,v,k in G.edges(keys=True, data=False) if 
(u==4515988732 and v==2021402216)]

但在这种情况下,我得到一个无效的 RGBA 参数错误。 我花了很多时间,但我是 osmnx 的新手,我无法找到正确的语法来实现我的目标:我哪里出错了?

【问题讨论】:

    标签: python osmnx


    【解决方案1】:

    OSMnx examples 演示了如何根据某些特征为边缘着色。

    ec = ['b' if (u==4515988732 and v==2021402216) else 'r' for u, v, k in G.edges(keys=True)]
    fig, ax = ox.plot_graph(G, node_color='w', node_edgecolor='k', node_size=30, 
                               node_zorder=3, edge_color=ec, edge_linewidth=3)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      • 2019-09-17
      • 2016-05-14
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多