You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the generation of multiple heatmaps at the same location, I noticed the generated html files keep increasing in size without an equivalent increase in the volume at a given map. Here are the resulting file sizes when I generate the same map with the same data for 200 times:
import os
import shutil
import tempfile
from pathlib import Path
import gmaps
import numpy as np
from ipywidgets.embed import embed_minimal_html
tmp = tempfile.mkdtemp()
coordinates = np.random.randint(10, 50, (50, 2)).astype('float64')
for i in range(200):
center = 20, 30
fig = gmaps.figure(center=center, zoom_level=10)
heatmap_layer = gmaps.heatmap_layer(coordinates)
heatmap_layer.max_intensity = 100
heatmap_layer.point_radius = 5
fig.add_layer(heatmap_layer)
p = Path(tmp) / f'{i}.html'
embed_minimal_html(p.as_posix(), views=[fig])
print(f'Current: {p.name}: {os.path.getsize(p.as_posix()) / 1024 ** 2} MB')
shutil.rmtree(tmp)
A temporary fix to the issue is to add the following to the code:
from ipywidgets.widgets.widget import Widget
And to include this line in the loop:
Widget.widgets.clear()
As gmaps.figure for some reason uses this object and keeps storing additional figure data inside it disregarding whether they are still needed. If this behavior is unintentional, I can issue a pr with the fix if there is one.
for i in range(200):
Widget.widgets.clear()
center = 20, 30
fig = gmaps.figure(center=center, zoom_level=10)
heatmap_layer = gmaps.heatmap_layer(coordinates)
heatmap_layer.max_intensity = 100
heatmap_layer.point_radius = 5
fig.add_layer(heatmap_layer)
p = Path(tmp) / f'{i}.html'
embed_minimal_html(p.as_posix(), views=[fig])
print(f'Current: {p.name}: {os.path.getsize(p.as_posix()) / 1024 ** 2} MB')
shutil.rmtree(tmp)
During the generation of multiple heatmaps at the same location, I noticed the generated html files keep increasing in size without an equivalent increase in the volume at a given map. Here are the resulting file sizes when I generate the same map with the same data for 200 times:
Result:
A temporary fix to the issue is to add the following to the code:
And to include this line in the loop:
As
gmaps.figure
for some reason uses this object and keeps storing additional figure data inside it disregarding whether they are still needed. If this behavior is unintentional, I can issue a pr with the fix if there is one.Result:
The text was updated successfully, but these errors were encountered: