Skip to content
Merged
Changes from all commits
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
20 changes: 13 additions & 7 deletions branca/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ def __init__(self, vmin=0., vmax=1., caption='', max_labels=10):
self.caption = caption
self.index = [vmin, vmax]
self.max_labels = max_labels
self.tick_labels = None

def render(self, **kwargs):
"""Renders the HTML representation of the element."""
self.color_domain = [self.vmin + (self.vmax-self.vmin) * k/499. for
k in range(500)]
self.color_range = [self.__call__(x) for x in self.color_domain]
self.tick_labels = legend_scaler(self.index, self.max_labels)
if self.tick_labels is None:
self.tick_labels = legend_scaler(self.index, self.max_labels)

super(ColorMap, self).render(**kwargs)

Expand Down Expand Up @@ -185,11 +187,13 @@ class LinearColormap(ColorMap):
The maximal value for the colormap.
Values higher than `vmax` will be bound directly to `colors[-1]`.
max_labels : int, default 10
Maximum number of legend tick labels"""

def __init__(self, colors, index=None, vmin=0., vmax=1., caption='', max_labels=10):
Maximum number of legend tick labels
tick_labels: list of floats, default None
If given, used as the positions of ticks."""
def __init__(self, colors, index=None, vmin=0., vmax=1., caption='', max_labels=10, tick_labels=None):
super(LinearColormap, self).__init__(vmin=vmin, vmax=vmax,
caption=caption, max_labels=max_labels)
self.tick_labels = tick_labels

n = len(colors)
if n < 2:
Expand Down Expand Up @@ -332,7 +336,7 @@ def to_step(self, n=None, index=None, data=None, method=None,
caption = self.caption

return StepColormap(colors, index=index, vmin=index[0], vmax=index[-1], caption=caption,
max_labels=max_labels)
max_labels=max_labels, tick_labels=self.tick_labels)

def scale(self, vmin=0., vmax=1., max_labels=10):
"""Transforms the colorscale so that the minimal and maximal values
Expand Down Expand Up @@ -375,11 +379,13 @@ class StepColormap(ColorMap):
Values higher than `vmax` will be bound directly to `colors[-1]`.
max_labels : int, default 10
Maximum number of legend tick labels

tick_labels: list of floats, default None
If given, used as the positions of ticks.
"""
def __init__(self, colors, index=None, vmin=0., vmax=1., caption='', max_labels=10):
def __init__(self, colors, index=None, vmin=0., vmax=1., caption='', max_labels=10, tick_labels=None):
super(StepColormap, self).__init__(vmin=vmin, vmax=vmax,
caption=caption, max_labels=max_labels)
self.tick_labels = tick_labels

n = len(colors)
if n < 1:
Expand Down