【地图可视化 】 folium
程序员文章站
2022-03-10 16:21:19
...
Table of Contents
# generated data
import numpy as np
data = (
np.random.normal(size=(100, 3)) *
np.array([[0.1, 0.1, 0.1]]) +
np.array([[40, 116.5, 1]])
).tolist()
data[:3]
[[39.98775070370018, 116.40015681705347, 0.9611913282025442],
[39.968792554458126, 116.62828603106253, 1.1275722906609456],
[40.10665675253578, 116.53681632670839, 1.0263507033800447]]
MAP create
folium.Map(
location=None, 地图的中心点
tiles='OpenStreetMap', 地图的样式
attr=None, 采用地图的来源 https://ditu.amap.com/abs 高德地图
zoom_start=10, 地图的范围 )
Heatmap
HeatMap(data).add_to(m)
data:[经度,维度]or[经度,纬度,权重]
import folium
from folium.plugins import HeatMap
m = folium.Map([39.93, 116.38], zoom_start=12,attr='https://ditu.amap.com/abs')
HeatMap(data).add_to(m)
# m.save(os.path.join('results', 'Heatmap.html'))
<folium.plugins.heat_map.HeatMap at 0x1f7a42dbe80>
m
Make this Notebook Trusted to load map: File -> Trust Notebook
m2 = folium.Map([39.93, 116.38], zoom_start=6)
HeatMap([i[:2] for i in data]).add_to(m2)
m2
Make this Notebook Trusted to load map: File -> Trust Notebook
CircleMarker
画圈圈
olium.CircleMarker(
location=[39.9,116.7], 中心点位置
radius=5, 圆的大小
popup='popup', # 为本展示
color='#6495ED',#圈的颜色
fill=True, 是否填充
fill_color='#6495ED' #填充颜色
).add_to(m2)
folium.CircleMarker(
location=[39.9,116.7],
radius=5,
popup='popup',
color='#6495ED',#圈的颜色0
fill=True,
fill_color='#6495ED' #填充颜色
).add_to(m2)
<folium.vector_layers.CircleMarker at 0x1f7a3c7a748>
m2
Make this Notebook Trusted to load map: File -> Trust Notebook
folium.CircleMarker 标记
folium.Marker(
[40.24,116.74], 标记位置
popup='<b>浮标上面的那个文字</b>' 标记文字
,icon=folium.Icon(color='green',icon='info-sign') 颜色和图标
)
folium.Marker([40.2,116.7],popup='<b>浮标上面的那个文字</b>').add_to(m2) # 定一个点,放到地图m上
folium.Marker([39.22,116.72],popup='<b>浮标上面的那个文字</b>',icon=folium.Icon(color='red')).add_to(m2)
# 把浮标变成红色
folium.Marker([40.24,115.74],popup='<b>浮标上面的那个文字</b>',icon=folium.Icon(color='green',icon='info-sign')).add_to(m2)
# 浮标改图样
<folium.map.Marker at 0x1f7a3b354e0>
m2
Make this Notebook Trusted to load map: File -> Trust Notebook
folium.PolyLine(
np.column_stack((np.random.random(40) + 41,np.random.random(40) + 115)).tolist(), list【纬度,经度】
weight=5, # 粗细
opacity=0.8, # 透明度
color='orange' # 颜色
).add_to(m2)
import numpy as np
folium.PolyLine(np.column_stack((np.random.random(40) + 41,np.random.random(40) + 115)).tolist(),
weight=5, # 粗细
opacity=0.8, # 透明度
color='orange').add_to(m2)
<folium.vector_layers.PolyLine at 0x1f7ab330668>
m2
Make this Notebook Trusted to load map: File -> Trust Notebook
map save
m2.save('map_2.html')