osmnx 补充笔记:get_edge_colors_by_attr &get_node_colors_by_attr

0 数据部分

osmnx 笔记: plot_graph_route & plot_graph_routes_UQI-LIUWJ的博客-CSDN博客 中1.1,1.2一致

edges_sh['length']=-edges_sh['length']
#取负号是为了让之后的可视化更好看些,没有实际意义

nx.set_edge_attributes(G_, edges_sh['length'], 'length')
#将 edges_sh['length']设置为 边的属性 length

 1  get_edge_colors_by_attr

1.1 基本使用方法

根据指定的边属性,或者各条边的颜色

osmnx.plot.get_edge_colors_by_attr(
    G, 
    attr, 
    num_bins=None, 
    cmap='viridis', 
    start=0, 
    stop=1, 
    na_color='none', 
    equal_size=False)

1.2 参数说明

G (networkx.MultiDiGraph输入图
attr (string边属性的名称(也就是我们用nx.set_edge_attributes 设置的属性名称)
num_bins (int

如果为None,则线性映射一个颜色到每个值。

否则,给这几个箱子赋值,然后给每个箱子分配颜色。

cmap (string)
start (float颜色空间的起始位置
stop (float颜色空间的结束位置
na_color (string给缺省值的颜色

 1.3 举例

ox.plot.plot_graph(G_,
                   edge_color=ox.plot.get_edge_colors_by_attr(
                       G_,
                       'length',
                       num_bins=3,
                       cmap='RdYlGn'),
                   figsize=(100,20))

 1.3.1 缺省值

maxspeed这一列,有很多的缺省值

edges_sh['maxspeed']=pd.to_numeric(edges_sh['maxspeed'])
#类型转换,从string转换至 float

nx.set_edge_attributes(G_, edges_sh['maxspeed'], 'max_speed')
#同样,设置边属性名称

ox.plot.plot_graph(G_,
                   edge_color=ox.plot.get_edge_colors_by_attr(
                       G_,
                       'max_speed',
                       num_bins=3,
                       cmap='RdYlGn',
                       na_color='black'),
                   figsize=(100,20))
#N属性为aN的边会被画成黑色

 2  get_node_colors_by_attr

osmnx.plot.get_node_colors_by_attr(
    G, 
    attr,
    num_bins=None, 
    cmap='viridis', 
    start=0, 
    stop=1, 
    na_color='none', 
    equal_size=False)

和get_edge_colors_by_attr 几乎一模一样

nx.set_node_attributes(G_,nodes_sh['street_count'],'street')
ox.plot.plot_graph(G_,
                   node_color=ox.plot.get_node_colors_by_attr(
                       G_,
                       'street',
                       num_bins=3,
                       cmap='RdYlGn',
                       na_color='black'),
                   node_size=100,
                   figsize=(100,20))

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UQI-LIUWJ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值