Skip to content

Commit d65324d

Browse files
Update examples/Velocity_with_colormap.ipynb
Co-authored-by: David Brochart <[email protected]>
1 parent 0903cf6 commit d65324d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

examples/Velocity_with_colormap.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"# Set up for JupyterLite\n",
2121
"try:\n",
2222
" import piplite\n",
23-
" await piplite.install(['ipyleaflet')\n",
23+
" await piplite.install('ipyleaflet')\n",
2424
"except ImportError:\n",
2525
" pass"
2626
]

ipyleaflet/velocity.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,25 @@ class Velocity(Layer):
6868
max_velocity = Float(10).tag(sync=True, o=True)
6969
velocity_scale = Float(0.005).tag(sync=True, o=True)
7070
colormap = Any(linear.YlOrRd_04)
71-
color_scale = List([]).tag(sync=True, o=True)
71+
#color_scale = List([]).tag(sync=True, o=True)
72+
colors = [
73+
"rgb(36,104, 180)",
74+
"rgb(60,157, 194)",
75+
"rgb(128,205,193)",
76+
"rgb(151,218,168)",
77+
"rgb(198,231,181)",
78+
"rgb(238,247,217)",
79+
"rgb(255,238,159)",
80+
"rgb(252,217,125)",
81+
"rgb(255,182,100)",
82+
"rgb(252,150,75)",
83+
"rgb(250,112,52)",
84+
"rgb(245,64,32)",
85+
"rgb(237,45,28)",
86+
"rgb(220,24,32)",
87+
"rgb(180,0,35)"
88+
]
89+
color_scale = List(colors).tag(sync=True, o=True)
7290

7391
@default('color_scale')
7492
def _default_color_scale(self):
@@ -80,3 +98,14 @@ def _default_color_scale(self):
8098
self.color_scale.append(rgb_str)
8199

82100
return self.color_scale
101+
102+
@default('colormap')
103+
def _default_colormap(self):
104+
105+
106+
for color in self.colormap.colors:
107+
rgb_tuple = tuple(int(x * 256) for x in color[:3])
108+
rgb_str = f"rgb{rgb_tuple}"
109+
self.color_scale.append(rgb_str)
110+
111+
return self.color_scale

0 commit comments

Comments
 (0)