Skip to content

Commit

Permalink
Various small fixes for plotly backend (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Jun 24, 2017
1 parent 707da2b commit c1a0283
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion holoviews/plotting/plot.py
Expand Up @@ -655,7 +655,7 @@ def _get_frame(self, key):
frame = get_plot_frame(self.hmap, key_map, cached)
traverse_setter(self, '_force', False)

if not key in self.keys:
if not key in self.keys and self.dynamic:
self.keys.append(key)
self.current_frame = frame
self.current_key = key
Expand Down
10 changes: 9 additions & 1 deletion holoviews/plotting/plotly/__init__.py
@@ -1,6 +1,6 @@
from ...core.options import Store, Cycle, Options
from ...core import (Overlay, NdOverlay, Layout, NdLayout, GridSpace,
GridMatrix)
GridMatrix, config)
from ...interface.seaborn import * # noqa (Element import for registration)
from ...element import * # noqa (Element import for registration)
from .renderer import PlotlyRenderer
Expand Down Expand Up @@ -30,6 +30,7 @@
Raster: RasterPlot,
Image: RasterPlot,
HeatMap: HeatMapPlot,
QuadMesh: QuadMeshPlot,

# 3D Plot
Scatter3D: Scatter3dPlot,
Expand All @@ -51,6 +52,7 @@

options = Store.options(backend='plotly')

dflt_cmap = 'hot' if config.style_17 else 'fire'

point_size = np.sqrt(6) # Matches matplotlib default
Cycle.default_cycles['default_colors'] = ['#30a2da', '#fc4f30', '#e5ae38',
Expand All @@ -62,3 +64,9 @@
options.Scatter = Options('style', color=Cycle())
options.Points = Options('style', color=Cycle())
options.Trisurface = Options('style', cmap='viridis')

# Rasters
options.Image = Options('style', cmap=dflt_cmap)
options.Raster = Options('style', cmap=dflt_cmap)
options.QuadMesh = Options('style', cmap=dflt_cmap)
options.HeatMap = Options('style', cmap='RdBu_r')
5 changes: 4 additions & 1 deletion holoviews/plotting/plotly/chart.py
Expand Up @@ -12,7 +12,7 @@ class ScatterPlot(ColorbarPlot):
allow_None=True, doc="""
Index of the dimension from which the color will the drawn""")

style_opts = ['symbol', 'color', 'cmap', 'fillcolor', 'opacity']
style_opts = ['symbol', 'color', 'cmap', 'fillcolor', 'opacity', 'fill', 'marker', 'size']

graph_obj = go.Scatter

Expand Down Expand Up @@ -216,3 +216,6 @@ def generate_plot(self, key, ranges):
fig = go.Figure(data=plots, layout=layout)
self.handles['fig'] = fig
return fig

def get_extents(self, element, ranges):
return (None, None, None, None)
15 changes: 14 additions & 1 deletion holoviews/plotting/plotly/element.py
@@ -1,6 +1,8 @@
import numpy as np
import plotly.graph_objs as go
import param

from ...core.util import basestring
from .plot import PlotlyPlot
from ..plot import GenericElementPlot, GenericOverlayPlot
from .. import util
Expand Down Expand Up @@ -211,7 +213,18 @@ def get_color_opts(self, dim, element, ranges, style):
else:
opts['showscale'] = False

opts['colorscale'] = style.pop('cmap', 'viridis')
cmap = style.pop('cmap', 'viridis')
if cmap == 'fire':
values = np.linspace(0, 1, len(util.fire_colors))
cmap = [(v, 'rgb(%d, %d, %d)' % tuple(c))
for v, c in zip(values, np.array(util.fire_colors)*255)]
elif isinstance(cmap, basestring):
if cmap[0] == cmap[0].lower():
cmap = cmap[0].upper() + cmap[1:]
if cmap.endswith('_r'):
cmap = cmap[:-2]
opts['reversescale'] = True
opts['colorscale'] = cmap
if dim:
cmin, cmax = ranges.get(dim.name, element.range(dim.name))
opts['cmin'] = cmin
Expand Down
7 changes: 4 additions & 3 deletions holoviews/plotting/plotly/raster.py
Expand Up @@ -39,9 +39,10 @@ def get_extents(self, element, ranges):
return (np.NaN,)*4

def get_data(self, element, ranges):
return (), dict(x=unique_array(element.dimension_values(0, False)),
y=unique_array(element.dimension_values(1, False)),
z=np.flipud(element.raster))
gridded = element.gridded.sort()
return (), dict(x=gridded.dimension_values(0, False),
y=gridded.dimension_values(1, False),
z=gridded.dimension_values(2, flat=False))


class QuadMeshPlot(RasterPlot):
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/plotly/tabular.py
@@ -1,5 +1,5 @@
import param
from plotly.tools import FigureFactory as FF
from plotly.figure_factory import create_table
from .element import ElementPlot


Expand All @@ -16,7 +16,7 @@ def get_data(self, element, ranges):
return (headings+data,), {}

def init_graph(self, plot_args, plot_kwargs):
return FF.create_table(*plot_args, **plot_kwargs)
return create_table(*plot_args, **plot_kwargs)


def graph_options(self, element, ranges):
Expand Down

0 comments on commit c1a0283

Please sign in to comment.