Skip to content

Commit

Permalink
use alpha channels of colors in colormap legend
Browse files Browse the repository at this point in the history
  • Loading branch information
BalthasarSchachtner committed Jul 12, 2019
1 parent 4e89e88 commit ac70858
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions branca/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -143,7 +149,7 @@ def _repr_html_(self):
[('<line x1="{i}" y1="0" x2="{i}" '
'y2="20" style="stroke:{color};stroke-width:3;" />').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)]) +
'<text x="0" y="35">{}</text>'.format(self.vmin) +
Expand Down

0 comments on commit ac70858

Please sign in to comment.