@TOC
folium 相比较于国内百度的 pyecharts 灵活性更强,能够自定义绘制区域,并且展现形式更加多样化。
各级别地图
世界地图
import folium
print(folium.__version__)
# define the world map
world_map = folium.Map()
# display world map
world_map
国家地图
市级地图
# define the city map
city_map = folium.Map(location=[39.93, 116.40], zoom_start=10)
# display city map
city_map
地图形式
更改tiles参数即可
# define the city map,tiles='Stamen Toner'
city_map = folium.Map(location=[39.93, 116.40], zoom_start=10, tiles='Stamen Toner')
# display city map
city_map
# define the city map, tiles='Stamen Terrain'
city_map = folium.Map(location=[39.93, 116.40], zoom_start=10, tiles='Stamen Terrain')
# display city map
city_map
普通标记
bj_map = folium.Map(location=[39.93, 116.40], zoom_start=12, tiles='Stamen Toner')
folium.Circle(
radius=200,
location=[39.92, 116.43],
popup='The Waterfront',
color='crimson',
fill=False,
).add_to(bj_map)
folium.CircleMarker(
location=[39.93, 116.38],
radius=50,
popup='Laurelhurst Park',
color='#3186cc',
fill=True,
fill_color='#3186cc'
).add_to(bj_map)
bj_map
圆形标记
bj_map = folium.Map(location=[39.93, 116.40], zoom_start=12, tiles='Stamen Toner')
folium.Circle(
radius=200,
location=[39.92, 116.43],
popup='The Waterfront',
color='crimson',
fill=False,
).add_to(bj_map)
folium.CircleMarker(
location=[39.93, 116.38],
radius=50,
popup='Laurelhurst Park',
color='#3186cc',
fill=True,
fill_color='#3186cc'
).add_to(bj_map)
bj_map
点击获取经纬度
m = folium.Map(location=[46.1991, -122.1889],tiles='Stamen Terrain',zoom_start=13)
m.add_child(folium.LatLngPopup())
m
动态放置标记
m = folium.Map(
location=[46.8527, -121.7649],
tiles='Stamen Terrain',
zoom_start=13
)
folium.Marker(
[46.8354, -121.7325],
popup='Camp Muir'
).add_to(m)
m.add_child(folium.ClickForMarker(popup='Waypoint'))
m
热力图标记
# 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()
print(data)
# HeatMap
from folium.plugins import HeatMap
m = folium.Map([39.93, 116.38], tiles='stamentoner', zoom_start=6)
HeatMap(data).add_to(m)
# m.save(os.path.join('results', 'Heatmap.html'))
m
密度图绘制
from folium.plugins import MarkerCluster
m = folium.Map([39.93, 116.38], tiles='stamentoner', zoom_start=10)
# create a mark cluster object
marker_cluster = MarkerCluster().add_to(m)
# add data point to the mark cluster
for lat, lng, label in data:
folium.Marker(
location=[lat, lng],
icon=None,
popup=label,
).add_to(marker_cluster)
# add marker_cluster to map
m.add_child(marker_cluster)
网友评论