main
parent
0f5c9391a0
commit
a03bfcb485
@ -0,0 +1,45 @@
|
||||
import pandas as pd
|
||||
import folium
|
||||
from folium.plugins import HeatMap
|
||||
import numpy as np
|
||||
|
||||
# 1. 定义朱诺市的中心坐标
|
||||
juneau_center = [58.3019, -134.4197]
|
||||
|
||||
# 2. 生成模拟数据(确保权重是数值类型)
|
||||
np.random.seed(42)
|
||||
num_points = 50
|
||||
lats = np.random.normal(juneau_center[0], 0.1, num_points)
|
||||
lons = np.random.normal(juneau_center[1], 0.1, num_points)
|
||||
weights = np.random.rand(num_points) # 确保权重是浮点数
|
||||
|
||||
data = [[lat, lon, weight] for lat, lon, weight in zip(lats, lons, weights)]
|
||||
|
||||
# 3. 创建地图对象
|
||||
m = folium.Map(
|
||||
location=juneau_center,
|
||||
zoom_start=12,
|
||||
tiles="cartodbpositron"
|
||||
)
|
||||
|
||||
# 4. 修复关键点:将 gradient 的键改为字符串格式
|
||||
HeatMap(
|
||||
data,
|
||||
radius=20,
|
||||
blur=15,
|
||||
max_zoom=13,
|
||||
gradient={'0.4': 'blue', '0.6': 'lime', '1': 'red'} # 键改为字符串
|
||||
).add_to(m)
|
||||
|
||||
# 5. 标记市中心
|
||||
folium.Marker(
|
||||
location=juneau_center,
|
||||
popup="Juneau, Alaska",
|
||||
icon=folium.Icon(color="green")
|
||||
).add_to(m)
|
||||
|
||||
# 6. 保存地图
|
||||
m.save("juneau_heatmap.html")
|
||||
|
||||
# 在Jupyter中显示
|
||||
# m
|
@ -0,0 +1,142 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<script>
|
||||
L_NO_TOUCH = false;
|
||||
L_DISABLE_3D = false;
|
||||
</script>
|
||||
|
||||
<style>html, body {width: 100%;height: 100%;margin: 0;padding: 0;}</style>
|
||||
<style>#map {position:absolute;top:0;bottom:0;right:0;left:0;}</style>
|
||||
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.css"/>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css"/>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.0/css/all.min.css"/>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css"/>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css"/>
|
||||
|
||||
<meta name="viewport" content="width=device-width,
|
||||
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<style>
|
||||
#map_1d3b9753142395a05ec6c71514f305be {
|
||||
position: relative;
|
||||
width: 100.0%;
|
||||
height: 100.0%;
|
||||
left: 0.0%;
|
||||
top: 0.0%;
|
||||
}
|
||||
.leaflet-container { font-size: 1rem; }
|
||||
</style>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/gh/python-visualization/folium@main/folium/templates/leaflet_heat.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<div class="folium-map" id="map_1d3b9753142395a05ec6c71514f305be" ></div>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
|
||||
|
||||
var map_1d3b9753142395a05ec6c71514f305be = L.map(
|
||||
"map_1d3b9753142395a05ec6c71514f305be",
|
||||
{
|
||||
center: [58.3019, -134.4197],
|
||||
crs: L.CRS.EPSG3857,
|
||||
...{
|
||||
"zoom": 12,
|
||||
"zoomControl": true,
|
||||
"preferCanvas": false,
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var tile_layer_8dcabcdfcdc48c6e889735abf1dffb8d = L.tileLayer(
|
||||
"https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png",
|
||||
{
|
||||
"minZoom": 0,
|
||||
"maxZoom": 20,
|
||||
"maxNativeZoom": 20,
|
||||
"noWrap": false,
|
||||
"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors \u0026copy; \u003ca href=\"https://carto.com/attributions\"\u003eCARTO\u003c/a\u003e",
|
||||
"subdomains": "abcd",
|
||||
"detectRetina": false,
|
||||
"tms": false,
|
||||
"opacity": 1,
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
|
||||
tile_layer_8dcabcdfcdc48c6e889735abf1dffb8d.addTo(map_1d3b9753142395a05ec6c71514f305be);
|
||||
|
||||
|
||||
var heat_map_6f867167adb2102e17ea753d8cd2e109 = L.heatLayer(
|
||||
[[58.35157141530112, -134.38729160306053, 0.417411003148779], [58.28807356988288, -134.45820822804163, 0.22210781047073025], [58.366668853810076, -134.4873922000306, 0.1198653673336828], [58.454202985640805, -134.35853237111593, 0.33761517140362796], [58.27848466252767, -134.3166000477504, 0.9429097039125192], [58.27848630430508, -134.32657198808838, 0.32320293202075523], [58.459821281550745, -134.50362175232226, 0.5187906217433661], [58.37864347291529, -134.45062123758512, 0.7030189588951778], [58.254952561406505, -134.38657365685964, 0.363629602379294], [58.3561560043586, -134.32214548728777, 0.9717820827209607], [58.255558230718755, -134.46761742378453, 0.9624472949421112], [58.25532702464298, -134.43826589766638, 0.25178229582536416], [58.326096227156604, -134.53033349740062, 0.49724850589238545], [58.11057197553422, -134.53932066240807, 0.30087830981676966], [58.1294082167487, -134.3384474177606, 0.2848404943774676], [58.245671247075904, -134.28407599714293, 0.036886947354532795], [58.20061688796656, -134.42690101215803, 0.6095643339798968], [58.33332473325953, -134.3193467102108, 0.5026790232288615], [58.211097592447885, -134.38353639749525, 0.05147875124998935], [58.160669629866476, -134.4842119754605, 0.27864646423661144], [58.44846487689216, -134.38356043944916, 0.9082658859666537], [58.27932236995135, -134.2658963433534, 0.23956189066697242], [58.308652820468794, -134.423282603911, 0.1448948720912231], [58.15942518137866, -134.2632356344186, 0.489452760277563], [58.24746172754749, -134.68167451040898, 0.9856504541106007], [58.31299225897099, -134.33750974956249, 0.2420552715115004], [58.18680064225777, -134.4109952931762, 0.6721355474058786], [58.33946980183457, -134.4496007350466, 0.7616196153287176], [58.24183613100812, -134.41052392234644, 0.23763754399239967], [58.27273062502068, -134.61845689146008, 0.7282163486118596], [58.24172933877706, -134.44166718878375, 0.3677831327192532], [58.487127818450894, -134.38398874284883, 0.6323058305935795], [58.30055027752621, -134.27191059552587, 0.6335297107608947], [58.196128907104416, -134.47152702182737, 0.5357746840747585], [58.384154491210325, -134.5005493602893, 0.0902897700544083], [58.1798156350029, -134.46987570435846, 0.835302495589238], [58.322786359500476, -134.3281597882298, 0.32078006497173583], [58.10593298761203, -134.38682488903405, 0.18651851039985423], [58.16908139511016, -134.4726760203767, 0.040775141554763916], [58.32158612358692, -134.36837325668867, 0.5908929431882418], [58.37574665799954, -134.4099922450652, 0.6775643618422824], [58.319036828119, -134.32283550094672, 0.016587828927856152], [58.29033517176118, -134.48990530938775, 0.512093058299281], [58.27178963044108, -134.45246621465978, 0.22649577519793795], [58.15404780096326, -134.45891081531323, 0.6451727904094499], [58.22991557916053, -134.56605149481322, 0.17436642900499144], [58.25583612290402, -134.39008797229354, 0.690937738102466], [58.40761222262189, -134.393594472782, 0.3867353463005374], [58.33626182895685, -134.41918865433576, 0.9367299887367345], [58.12559598446373, -134.4431587133375, 0.13752094414599325]],
|
||||
{
|
||||
"minOpacity": 0.5,
|
||||
"maxZoom": 13,
|
||||
"radius": 20,
|
||||
"blur": 15,
|
||||
"gradient": {
|
||||
"0.4": "blue",
|
||||
"0.6": "lime",
|
||||
"1": "red",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
heat_map_6f867167adb2102e17ea753d8cd2e109.addTo(map_1d3b9753142395a05ec6c71514f305be);
|
||||
|
||||
|
||||
var marker_c4c30c75a0b2c7bc05c20782031e95a6 = L.marker(
|
||||
[58.3019, -134.4197],
|
||||
{
|
||||
}
|
||||
).addTo(map_1d3b9753142395a05ec6c71514f305be);
|
||||
|
||||
|
||||
var icon_49c9a22f982eb821c5a2ba0985ada420 = L.AwesomeMarkers.icon(
|
||||
{
|
||||
"markerColor": "green",
|
||||
"iconColor": "white",
|
||||
"icon": "info-sign",
|
||||
"prefix": "glyphicon",
|
||||
"extraClasses": "fa-rotate-0",
|
||||
}
|
||||
);
|
||||
marker_c4c30c75a0b2c7bc05c20782031e95a6.setIcon(icon_49c9a22f982eb821c5a2ba0985ada420);
|
||||
|
||||
|
||||
var popup_554c8ee4784f62842b97ff31e7fa83f1 = L.popup({
|
||||
"maxWidth": "100%",
|
||||
});
|
||||
|
||||
|
||||
|
||||
var html_7833cf3a7b11badbf374ec56e8d602cc = $(`<div id="html_7833cf3a7b11badbf374ec56e8d602cc" style="width: 100.0%; height: 100.0%;">Juneau, Alaska</div>`)[0];
|
||||
popup_554c8ee4784f62842b97ff31e7fa83f1.setContent(html_7833cf3a7b11badbf374ec56e8d602cc);
|
||||
|
||||
|
||||
|
||||
marker_c4c30c75a0b2c7bc05c20782031e95a6.bindPopup(popup_554c8ee4784f62842b97ff31e7fa83f1)
|
||||
;
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in new issue