From e2dbd39c350c331c608811f57090e136e116e712 Mon Sep 17 00:00:00 2001 From: Balthasar Schachtner Date: Sat, 13 Jul 2019 00:15:34 +0200 Subject: [PATCH] use alpha channels of colors in colormap legend --- branca/colormap.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/branca/colormap.py b/branca/colormap.py index 67f24b1..6650b1f 100644 --- a/branca/colormap.py +++ b/branca/colormap.py @@ -126,15 +126,21 @@ def rgb_bytes_tuple(self, x): def rgb_hex_str(self, x): """Provides the color corresponding to value `x` in the - form of a string of hewadecimal values "#RRGGBB". + form of a string of hexadecimal values "#RRGGBB". """ return '#%02x%02x%02x' % self.rgb_bytes_tuple(x) + def rgba_hex_str(self, x): + """Provides the color corresponding to value `x` in the + form of a string of hexadecimal values "#RRGGBBAA". + """ + return '#%02x%02x%02x%02x' % self.rgba_bytes_tuple(x) + def __call__(self, x): """Provides the color corresponding to value `x` in the - form of a string of hewadecimal values "#RRGGBB". + form of a string of hexadecimal values "#RRGGBBAA". """ - return self.rgb_hex_str(x) + return self.rgba_hex_str(x) def _repr_html_(self): return ( @@ -143,7 +149,7 @@ def _repr_html_(self): [('').format( i=i*1, - color=self.rgb_hex_str(self.vmin + + color=self.rgba_hex_str(self.vmin + (self.vmax-self.vmin)*i/499.)) for i in range(500)]) + '{}'.format(self.vmin) +