Skip to content

Commit

Permalink
Merge pull request #64 from BalthasarSchachtner/ColormapAlpha
Browse files Browse the repository at this point in the history
Colormap alpha
  • Loading branch information
ocefpaf authored Jul 17, 2019
2 parents e3c9583 + f6fe71d commit 291b8e7
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 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,8 +149,10 @@ 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 +
(self.vmax-self.vmin)*i/499.))
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) +
'<text x="500" y="35" style="text-anchor:end;">{}</text>'.format(
Expand Down

0 comments on commit 291b8e7

Please sign in to comment.