Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_heat_map():
np.random.seed(3141592)
data = (np.random.normal(size=(100, 2)) * np.array([[1, 1]]) +
np.array([[48, 5]])).tolist()
m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
hm = plugins.HeatMap(data)
m.add_child(hm)
m._repr_html_()
out = normalize(m._parent.render())
# We verify that the script import is present.
script = '' # noqa
assert script in out
# We verify that the script part is correct.
tmpl = Template("""
var {{this.get_name()}} = L.heatLayer(
{{this.data}},
{
minOpacity: {{this.min_opacity}},
maxZoom: {{this.max_zoom}},
if not end:
end = df.index[-1]
df = df[start:end].dropna()
meanlat, meanlong = df.mean()
heatmap = folium.Map(location=[meanlat, meanlong],
control_scale=True,
zoom_start=12)
point_tuples = zip(df.lat, df.long)
points = [[la, lo] for la, lo in point_tuples]
cluster = plugins.HeatMap(data=points,
name="heatmap",
radius=5)
heatmap.add_children(cluster)
return heatmap
for i in vars(args):
print(str(i) + ' - ' + str(getattr(args, i)))
print('-' * 50)
location = [float(i) for i in args.map_location]
for_map = pd.read_csv(args.csv, sep=';')
max_amount = float(args.max_value) if args.max_value else float(for_map['magnitude'].max())
map = folium.Map(location=location,
zoom_start=args.map_zoom_start,
tiles=args.tiles)
map_data = [[row['lat'], row['lon'], row['magnitude']] for index, row in for_map.iterrows()]
heatmap = folium.plugins.HeatMap(map_data,
max_val=max_amount,
min_opacity=args.heatmap_min_opocity,
radius=args.heatmap_radius,
blur=args.heatmap_blur,
max_zoom=args.heatmap_max_zoom)
map.add_child(heatmap)
map.save(args.output)
this.feature_group.addLayer(marker);
}
{{this._parent.get_name()}}.addLayer(this.feature_group);
{% if this.fit_bounds %}{{this._parent.get_name()}}
.fitBounds(this.feature_group.getBounds());{% endif %}
}
dc.dataTable('#foo')
.dimension({{this.crossfilter.get_name()}}.allDim)
.group(function (d) { return 'dc.js';})
.on('renderlet', function (table) { {{this.get_name()}}.updateFun();});
{{this.get_name()}}.updateFun();
{% endmacro %}
""")
class HeatmapFilter(HeatMap):
def __init__(self, crossfilter, name=None, fit_bounds=False, **kwargs):
"""
"""
super(HeatmapFilter, self).__init__([], **kwargs)
self._name = 'HeatmapFilter'
self.crossfilter = crossfilter
self.fit_bounds = fit_bounds
self._template = Template(u"""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = {};
{{this.get_name()}}.heatmap = new L.heatLayer(
{},
{
minOpacity: {{this.min_opacity}},
"""
if base_map is None:
base_map = create_base_map(
move_data,
lat_origin,
lon_origin,
tile=tile,
default_zoom_start=zoom_start,
)
if n_rows is None:
n_rows = move_data.shape[0]
move_data[COUNT] = 1
HeatMap(
data=move_data.iloc[:n_rows][[LATITUDE, LONGITUDE, COUNT]]
.groupby([LATITUDE, LONGITUDE])
.sum()
.reset_index()
.values.tolist(),
radius=radius
).add_to(base_map)
move_data.drop(columns=COUNT, inplace=True)
if save_as_html:
base_map.save(outfile=filename)
else:
return base_map
:param locations: 样本的省市区, pandas的dataframe类型.
:param file_path: 生成的html文件的路径.
"""
_base_input_check(locations)
import folium
from folium.plugins import HeatMap
# 注意判断key是否存在
heatData = []
for map_key in zip(locations["省"], locations["市"], locations["区"]):
if latlng.get(map_key):
lat_lon = latlng.get(map_key)
heatData.append([float(lat_lon[0]), float(lat_lon[1]), 1])
# 绘制Map,开始缩放程度是5倍
map_osm = folium.Map(location=[35, 110], zoom_start=5)
# 将热力图添加到前面建立的map里
HeatMap(heatData).add_to(map_osm)
# 保存为html文件
map_osm.save(file_path)