diff --git a/doc/Tutorials/Bokeh_Backend.ipynb b/doc/Tutorials/Bokeh_Backend.ipynb index 2766258174..4658444dc7 100644 --- a/doc/Tutorials/Bokeh_Backend.ipynb +++ b/doc/Tutorials/Bokeh_Backend.ipynb @@ -311,35 +311,8 @@ { "cell_type": "markdown", "metadata": { - "focus": false, - "id": "85e1ed20-1e12-4194-822e-c2fe0810ce41" - }, - "source": [ - "### Matplotlib/Seaborn conversions\n", - "\n", - "Bokeh also allows converting a subset of existing matplotlib plot types to Bokeh. This allows us to work with some of the Seaborn plot types, including Distribution, Bivariate, and TimeSeries:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false, - "focus": false, - "id": "f406d9f0-8488-4b0b-9bf2-95477aad104b" - }, - "outputs": [], - "source": [ - "%%opts Distribution (kde_kws=dict(shade=True))\n", - "d1 = np.random.randn(500) + 450\n", - "d2 = np.random.randn(500) + 540\n", - "sines = np.array([np.sin(np.linspace(0, np.pi*2, 100)) + np.random.normal(0, 1, 100) for _ in range(20)])\n", - "hv.Distribution(d1) + hv.Bivariate((d1, d2)) + hv.TimeSeries(sines)" - ] - }, - { - "cell_type": "markdown", - "metadata": { + "deletable": true, + "editable": true, "focus": false, "id": "fd1916ba-13a5-404a-8115-f63487b38689" }, diff --git a/holoviews/plotting/bokeh/__init__.py b/holoviews/plotting/bokeh/__init__.py index 98f9c82afe..c55e647176 100644 --- a/holoviews/plotting/bokeh/__init__.py +++ b/holoviews/plotting/bokeh/__init__.py @@ -19,7 +19,7 @@ from .annotation import TextPlot, LineAnnotationPlot, SplinePlot from .callbacks import Callback # noqa (API import) -from .element import OverlayPlot, BokehMPLWrapper +from .element import OverlayPlot from .chart import (PointPlot, CurvePlot, SpreadPlot, ErrorPlot, HistogramPlot, SideHistogramPlot, BoxPlot, BarPlot, SpikesPlot, SideSpikesPlot, AreaPlot, VectorFieldPlot) @@ -98,25 +98,6 @@ except ImportError: pass -try: - from ..mpl.seaborn import TimeSeriesPlot, BivariatePlot, DistributionPlot - from ...interface.seaborn import Bivariate, TimeSeries, Distribution - Store.register({Distribution: PlotSelector(lambda x: 'bokeh', - [('mpl', DistributionPlot), - ('bokeh', BokehMPLWrapper)], - True), - TimeSeries: PlotSelector(lambda x: 'bokeh', - [('mpl', TimeSeriesPlot), - ('bokeh', BokehMPLWrapper)], - True), - Bivariate: PlotSelector(lambda x: 'bokeh', - [('mpl', BivariatePlot), - ('bokeh', BokehMPLWrapper)], True)}, - 'bokeh') -except ImportError: - pass - - point_size = np.sqrt(6) # Matches matplotlib default Cycle.default_cycles['default_colors'] = ['#30a2da', '#fc4f30', '#e5ae38', '#6d904f', '#8b8b8b'] diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index 736570996e..ffbfa39dd5 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -2,6 +2,7 @@ from itertools import groupby import warnings +import param import numpy as np import bokeh import bokeh.plotting @@ -18,11 +19,6 @@ from bokeh.models import LogTicker, BasicTicker from bokeh.plotting.helpers import _known_tools as known_tools -try: - from bokeh import mpl -except ImportError: - mpl = None -import param from ...core import (Store, HoloMap, Overlay, DynamicMap, CompositeOverlay, Element, Dimension) @@ -1059,99 +1055,6 @@ def _process_legend(self, plot=None): legend.location = pos - -class BokehMPLWrapper(ElementPlot): - """ - Wraps an existing HoloViews matplotlib plot and converts - it to bokeh. - """ - - def __init__(self, element, plot=None, **params): - super(ElementPlot, self).__init__(element, **params) - if isinstance(element, HoloMap): - etype = element.type - else: - etype = type(element) - plot = Store.registry['matplotlib'][etype] - params = dict({k: v.default for k, v in self.params().items() - if k in ['bgcolor']}) - params = dict(params, **self.lookup_options(element, 'plot').options) - style = self.lookup_options(element, 'style') - self.mplplot = plot(element, style=style, **params) - - - def initialize_plot(self, ranges=None, plot=None, plots=None): - self.mplplot.initialize_plot(ranges) - - plot = plot if plot else self.handles.get('plot') - new_plot = mpl.to_bokeh(self.mplplot.state) - if plot: - update_plot(plot, new_plot) - else: - plot = new_plot - - self.handles['plot'] = plot - if not self.overlaid: - self._update_plot(self.keys[-1], plot, self.hmap.last) - return plot - - - def _update_plot(self, key, plot, element=None): - """ - Updates plot parameters on every frame - """ - plot.update(**self._plot_properties(key, plot, element)) - - def update_frame(self, key, ranges=None, plot=None, element=None, empty=False): - self.mplplot.update_frame(key, ranges) - - reused = isinstance(self.hmap, DynamicMap) and self.overlaid - if not reused and element is None: - element = self._get_frame(key) - else: - self.current_key = key - self.current_frame = element - - plot = mpl.to_bokeh(self.mplplot.state) - update_plot(self.handles['plot'], plot) - if not self.overlaid: - self._update_plot(key, self.handles['plot'], element) - - -class BokehMPLRawWrapper(BokehMPLWrapper): - """ - Wraps an existing HoloViews matplotlib plot, renders it as - an image and displays it as a HoloViews object. - """ - - def initialize_plot(self, ranges=None, plot=None, plots=None): - element = self.hmap.last - self.mplplot.initialize_plot(ranges) - plot = self._render_plot(element, plot) - self.handles['plot'] = plot - return plot - - def _render_plot(self, element, plot=None): - from .raster import RGBPlot - bytestream = BytesIO() - renderer = self.mplplot.renderer.instance(dpi=120) - renderer.save(self.mplplot, bytestream, fmt='png') - group = ('RGB' if element.group == type(element).__name__ else - element.group) - rgb = RGB.load_image(bytestream, bare=True, group=group, - label=element.label) - plot_opts = self.lookup_options(element, 'plot').options - rgbplot = RGBPlot(rgb, **plot_opts) - return rgbplot.initialize_plot(plot=plot) - - - def update_frame(self, key, ranges=None, element=None): - element = self.get_frame(key) - if key in self.hmap: - self.mplplot.update_frame(key, ranges) - self.handles['plot'] = self._render_plot(element) - - class OverlayPlot(GenericOverlayPlot, LegendPlot): tabs = param.Boolean(default=False, doc="""