How to wrap an existing Boheh plot into HoloViews?

Hi all,

Is it possible to wrap an existing plot into HoloViews so that it can interact with other elements as usual? It will be handy when a corresponding Element type is unavailable.

For example, how to make the following plot available in HoloViews? Thanks

from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.sampledata.sprint import sprint

output_file("bar_intervals.html")

sprint.Year = sprint.Year.astype(str)
group = sprint.groupby('Year')
source = ColumnDataSource(group)

p = figure(y_range=group, x_range=(9.5,12.7), plot_width=400, plot_height=550, toolbar_location=None,
           title="Time Spreads for Sprint Medalists (by Year)")
p.hbar(y="Year", left='Time_min', right='Time_max', height=0.4, source=source)

p.ygrid.grid_line_color = None
p.xaxis.axis_label = "Time (seconds)"
p.outline_line_color = None

show(p)

So this is a bit of hack and doesn’t support some of the features usually supported by other elements but it at least makes it possible to embed a static bokeh figure in a HoloViews layout. It does not support overlaying (with *) or updating in a DynamicMap and/or HoloMap:

from holoviews.core import Element
from holoviews.plotting.bokeh import ElementPlot

class BokehPlot(Element):
   """
   Allows embedding a bokeh figure in a HoloViews layout.
   """

class BokehFigurePlot(ElementPlot):
    
    def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
        plot = self.hmap.last.data
        self.handles['plot'] = plot
        return plot

hv.Store.register({BokehPlot: BokehFigurePlot}, 'bokeh')

BokehPlot(p) + hv.Curve([1, 2, 3])

If you just need to lay out a plot like this it probably ends up being cleaner to just use Panel to compose the HoloViews and Bokeh plots.