并排显示两个Folium地图?

9
如何将两个folium地图并排显示?(类似下面的图片,但我想展示的是folium地图而不是matplotlib图表) enter image description here 编辑:我想在jupyter笔记本中展示这些地图。以下是我当前的代码,它会垂直(堆叠)展示两个地图。
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

你能展示一下你的代码是什么样子吗? - Yaakov Bressler
此外,展示两张地图在哪里? - sentence
在Jupyter Notebook中。 - M. Chavoshi
1个回答

5

这是我能想出来的解决方案

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)

你可能需要对CircleMaker中的文本进行格式化,不包含单引号或其他特殊字符,以便正确嵌入到iframe中。
nyc_df= nyc_df(to_replace=r'\'', value="", regex=True)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接