Skip to main content
 首页 » 编程设计

python之在 map 上放置更多的 folium/leaflet 元素

2024年12月31日26lyj

Folium 是基于 Leaflet.js 使用 Python 制作交互式 map 的绝佳工具。

这里我用它在 map 上绘制图形。

the_map = folium.Map(tiles="cartodbpositron") 
for (u, v) in G.edges(): 
    if (not bbox) or (in_bbox(u) and in_bbox(v)): 
        folium.PolyLine( 
            locations=[positions[u][::-1], positions[v][::-1]], 
            weight=edge_size_attr[frozenset((u,v))], 
            color=get_edge_color(u, v), 
            tooltip=get_edge_tooltip(u, v) 
        ).add_to(the_map) 
return the_map 

工作正常。唯一的问题是可以用这种方式绘制的边数有硬性限制。超过几百,Leaflet 似乎认输了,不再渲染 map 。

我可以做些什么来突破极限并绘制更多的节点和边吗?

请您参考如下方法:

一种可能的解决方案:

jupyter notebook --NotebookApp.iopub_data_rate_limit=<LARGE_NUMBER> 

启动 jupyter 笔记本时,您可以允许更高的 iopub 速率,(@ https://github.com/jupyter/notebook/issues/2287 使用了 LARGE_NUMBER==10000000000)。

请谨慎行事,jupyter 在这里设置了一个下限以避免使您的客户端崩溃。