简体   繁体   English

并排显示两个 Folium 地图?

[英]showing two Folium maps side by side?

How can I show two folium maps side by side?如何并排显示两个大叶地图? (something like the image below, but instead of matplotlib charts I want folium maps to be shown) (类似于下图,但我想要显示大叶地图而不是 matplotlib 图表) 在此处输入图片说明

edit: I want to show these maps in a jupyter notebook.编辑:我想在 jupyter notebook 中显示这些地图。 and here's my current code with shows two maps vertically (stacked).这是我当前的代码,垂直显示两个地图(堆叠)。

map_toronto = folium.Map(location=[43.6532, -79.3832], zoom_start=11)

# add markers to map
for lat, lng, borough in zip(toronto_df['Latitude'], toronto_df['Longitude'], toronto_df['District']):
    label = '{}'.format(borough)
    label = folium.Popup(label, parse_html=True)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=0.7,
        parse_html=False).add_to(map_toronto)  

map_toronto
map_nyc = folium.Map(location=[40.7128, -74.0060], zoom_start=10)

# add markers to map
for lat, lng, borough in zip(nyc_df['Latitude'], nyc_df['Longitude'], nyc_df['District']):
    label = '{}'.format(borough)
    label = folium.Popup(label, parse_html=True)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=0.7,
        parse_html=False).add_to(map_nyc)  

map_nyc

Here is the solution I was able to come up with这是我能够想出的解决方案

from IPython.core.display import display, HTML

htmlmap = HTML('<iframe srcdoc="{}" style="float:left; width: {}px; height: {}px; display:inline-block; width: 50%; margin: 0 auto; border: 2px solid black"></iframe>'
           '<iframe srcdoc="{}" style="float:right; width: {}px; height: {}px; display:inline-block; width: 50%; margin: 0 auto; border: 2px solid black"></iframe>'
           .format(map_toronto.get_root().render().replace('"', '&quot;'),500,500,
                   map_nyc.get_root().render().replace('"', '&quot;'),500,500))
display(htmlmap)

You may need to format the text in the CircleMaker to not include single tick characters or other special characters to embed it in the iframe properly您可能需要在 CircleMaker 中格式化文本以不包含单个刻度字符或其他特殊字符以将其正确嵌入 iframe

nyc_df= nyc_df(to_replace=r'\'', value="", regex=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM