小册子朱皮特情节颜色密度热图

时间:2018-07-10 13:53:00

标签: python leaflet jupyter

我正在研究熊猫csv数据框,并使用ipyleaflet在jupyter中了解到,您可以绘制到地图上。

到目前为止,我的代码看起来像这样

from ipyleaflet import Map, Marker, MarkerCluster

longitudes = df['Longitude'].values.tolist()
latitudes = df['Latitude'].values.tolist()

markers = []

for lon,lat in zip(longitudes, latitudes):
    markers.append(Marker(location=(lat, lon)))

m = Map(center=(latitudes[0], longitudes[0]), zoom=10)

marker_cluster = MarkerCluster(
    markers=markers
)

m.add_layer(marker_cluster);

m

enter image description here

哪个很好,但是后来我看到了

enter image description here

我也有相同的字段Economic Need Index,所以我也想这样做,也很好奇如何切换到CartoDB不太忙的地图。

1 个答案:

答案 0 :(得分:0)

last version of ipyleaflet起,现在可以创建HeatMap:

from ipyleaflet import Map, Heatmap
from random import uniform

m = Map(center=[0, 0], zoom=2)

# Create a random heatmap
locations = [
    [uniform(-80, 80), uniform(-180, 180), uniform(0, 1000)] # lat, lng, intensity 
    for i in range(1000)
]
heat = Heatmap(locations=locations, radius=20, blur=10)
m.add_layer(heat)

# Change some attributes of the heatmap
heat.radius = 30
heat.blur = 50
heat.max = 0.5
heat.gradient = {0.4: 'red', 0.6: 'yellow', 0.7: 'lime', 0.8: 'cyan', 1.0: 'blue'}

m

此外,如果要切换到“不太忙的地图”,则可以在创建底图时更改底图:

from ipyleaflet import Map, basemaps

m = Map(center=(52, 10), zoom=8, basemap=basemaps.CartoDB.DarkMatter)
m

您还可以在给定图块的URL的情况下创建TileLayer,您可以在documentation

中找到示例