Skip to content

Commit

Permalink
Define Palettes and Cycles from backend specific colormaps/palettes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Jun 25, 2017
1 parent c1a0283 commit d57bfb6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 6 additions & 1 deletion holoviews/core/options.py
Expand Up @@ -252,7 +252,12 @@ class Cycle(param.Parameterized):

default_cycles = {'default_colors': []}

def __init__(self, **params):
def __init__(self, cycle=None, **params):
if cycle is not None:
if isinstance(cycle, basestring):
params['key'] = cycle
else:
params['values'] = cycle
super(Cycle, self).__init__(**params)
self.values = self._get_values()

Expand Down
13 changes: 12 additions & 1 deletion holoviews/plotting/bokeh/__init__.py
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import numpy as np
from bokeh.palettes import all_palettes

from ...core import (Store, Overlay, NdOverlay, Layout, AdjointLayout,
GridSpace, GridMatrix, NdLayout, config)
Expand All @@ -9,7 +10,7 @@
Box, Bounds, Ellipse, Polygons, BoxWhisker,
ErrorBars, Text, HLine, VLine, Spline, Spikes,
Table, ItemTable, Area, HSV, QuadMesh, VectorField)
from ...core.options import Options, Cycle
from ...core.options import Options, Cycle, Palette

try:
from ...interface import DFrame
Expand Down Expand Up @@ -106,6 +107,16 @@
Cycle.default_cycles['default_colors'] = ['#30a2da', '#fc4f30', '#e5ae38',
'#6d904f', '#8b8b8b']

# Register bokeh.palettes with Palette and Cycle
def colormap_generator(palette):
return lambda value: palette[int(value*(len(palette)-1))]

Palette.colormaps.update({name: colormap_generator(p[max(p.keys())])
for name, p in all_palettes.items()})

Cycle.default_cycles.update({name: p[max(p.keys())] for name, p in all_palettes.items()
if max(p.keys()) < 256})

dflt_cmap = 'hot' if config.style_17 else 'fire'
options = Store.options(backend='bokeh')

Expand Down
6 changes: 4 additions & 2 deletions holoviews/plotting/mpl/__init__.py
Expand Up @@ -2,6 +2,7 @@
from distutils.version import LooseVersion

from matplotlib import rc_params_from_file
from matplotlib.colors import ListedColormap

from ...core import Layout, Collator, GridMatrix, config
from ...core.options import Cycle, Palette, Options
Expand Down Expand Up @@ -73,10 +74,11 @@ def get_color_cycle():
Cycle.default_cycles['default_colors'] = ['#30a2da', '#fc4f30', '#e5ae38',
'#6d904f', '#8b8b8b']


# Filter spectral colormaps to avoid warning in mpl 2.0
# Define Palettes and cycles from matplotlib colormaps
Palette.colormaps.update({cm: plt.get_cmap(cm) for cm in plt.cm.datad
if 'spectral' not in cm and 'Vega' not in cm})
listed_cmaps = [cm for cm in Palette.colormaps.values() if isinstance(cm, ListedColormap)]
Cycle.default_cycles.update({cm.name: list(cm.colors) for cm in listed_cmaps})

style_aliases = {'edgecolor': ['ec', 'ecolor'], 'facecolor': ['fc'],
'linewidth': ['lw'], 'edgecolors': ['ec', 'edgecolor'],
Expand Down

0 comments on commit d57bfb6

Please sign in to comment.