Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Heatmap_with_colormap.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"outputs": [],
"source": [
"m = ipyleaflet.Map(center=[0, 0], zoom=2)\n",
"heat = ipyleaflet.Heatmap(locations=create_random_data(1000), radius=20, blur=10, gradient={0.1 : 'orange', 0.2 : 'red', 1.0 :'black'})\n",
"heat = ipyleaflet.Heatmap(locations=create_random_data(1000), radius=20, blur=10, gradient={1.0: 'black', 0.2 : 'red', 0.1 : 'orange'})\n",
"colormap_control = ipyleaflet.ColormapControl(\n",
" caption='Intensity',\n",
" colormap=heat.colormap,\n",
Expand Down
11 changes: 8 additions & 3 deletions ipyleaflet/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,8 @@ class Heatmap(RasterLayer):
max = Float(1.0).tag(sync=True, o=True)
radius = Float(25.0).tag(sync=True, o=True)
blur = Float(15.0).tag(sync=True, o=True)
gradient = Dict({0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1.0: 'red'}).tag(sync=True, o=True)
#gradient = Dict({0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1.0: 'red'}).tag(sync=True, o=True)
gradient = Dict({ 0.8: 'yellow', 0.6: 'cyan', 0.4: 'blue', 0.7: 'lime', 1.0: 'red'}).tag(sync=True, o=True)

def __init__(self, **kwargs):
super(Heatmap, self).__init__(**kwargs)
Expand All @@ -831,8 +832,12 @@ def _updata_data(self, change):
self.data = self._get_data()

def _get_data(self):
colormap_labels = list(self.gradient.keys())
colors = list(self.gradient.values())
sorted_gradient = {}
sorted_keys = sorted(self.gradient.keys())
for key in sorted_keys:
sorted_gradient[key] = self.gradient[key]
colormap_labels = list(sorted_gradient.keys())
colors = list(sorted_gradient.values())
self.vmin = colormap_labels[0]
self.vmax = colormap_labels[-1]
self.colormap = LinearColormap(colors=colors, index=colormap_labels, vmin=self.vmin, vmax=self.vmax)
Expand Down