建议使用Jupyter notebook
这里的效果展示的地图都是可以放大缩小的。在放大缩小的过程中图像会发生变化,尤其是热力图和气泡图。
所以最好自己运行一下,看看效果。
folium绘制地图 先随便调用一下:
1 2 3 4 5 6 import foliumimport pandas as pdworld_map = folium.Map() world_map
效果:
绘制基础图,添加标签,图形:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 latitude = 42.941335 longitude = -76.735501 map1 = folium.Map(location=[latitude, longitude], zoom_start=12 , tiles="Stamen Terrain" ) folium.Marker(location=[latitude, longitude], popup='<p style="width: 100px; font-family: Times New Roma">this is north area' ).add_to(map1) folium.Circle(location=[latitude, longitude], radius=1000 , color="green" , fill=True , fill_color="orange" ).add_to(map1) trail_coordinates = [ (42.931934 , -76.735210 ), (42.873589 , -76.719417 ), (42.807633 , -76.728343 ), (42.785464 , -76.740016 ), (42.739589 , -76.732463 ) ] folium.PolyLine(trail_coordinates, tooltip="Coast" ).add_to(map1) folium.Polygon([ [42.929101 , -76.745247 ], [42.926355 , -76.748130 ], [42.915337 , -76.729174 ], [42.917822 , -76.731963 ], [42.921067 , -76.733081 ], ],color='red' , weight=1 , fill=True , fill_color='red' , fill_opacity=0.3 ).add_to(map1) map1.save('map.html' ) map1
效果:
地点标记、绿边圆圈(橙色填圆圈)、红色面(浅红色填色)
展示蓝色线:
数据(point):
画热力图:
1 2 3 4 5 6 7 8 9 from folium.plugins import HeatMapmap1 = folium.Map(location=[latitude, longitude], zoom_start= 12 , tiles="Stamen Terrain" ) HeatMap(point[['x' , 'y' ]].values.tolist()).add_to(map1) map1.save('map2.html' ) map1
效果:
选择一个区域放大:
绘制气泡图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 incidents = folium.map .FeatureGroup() for i in range (1516 ): incidents.add_child( folium.CircleMarker( (point['x' ][i], point['y' ][i]), radius=7 , color='yellow' , fill=True , fill_color='red' , fill_opacity=0.4 ) ) map1 = folium.Map(location=[latitude, longitude], zoom_start=12 ) map1.add_child(incidents) map1.save("map3.html" ) map1
效果(数据越多,颜色越深):
放大北区,放大后一些点就会分开,更详细展示:
统计展示区域数量:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from folium import pluginsmap1 = folium.Map(location = [latitude, longitude], zoom_start = 12 ) incidents = plugins.MarkerCluster().add_to(map1) for lat, lng, label, in zip (point.x, point.y, point.m): folium.Marker( location=[lat, lng], icon=None , popup=label, ).add_to(incidents) map1.add_child(incidents) map1.save('map4.html' ) map1
效果(放大会分开,缩小会合并。数字代表这小块区域的点数量):
利用GeoJson产生地理分块(自己去网上找 url ,我这里是成都市的):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import jsonimport requestslatitude = 30.652154 longitude = 104.067411 url = "https://geo.datav.aliyun.com/areas_v3/bound/510100_full.json" cd_geo = f'{url} ' cd_map = folium.Map(location = [latitude, longitude], zoom_start = 9 ) folium.GeoJson( cd_geo, style_function=lambda feature: { 'fillColor' : '#ffff00' , 'color' : 'black' , 'weight' : 2 , 'dashArray' : '5, 5' , 'fillOpacity' : 0.6 } ).add_to(cd_map) cd_map.save("map5.html" ) cd_map
效果:
我这里是没有具体数据,如果有数据,可以做分块的数据热力图。
但是这样做其实效率不高。可以用PPT做,修改更加自由,效果: