Dynamic plot layout

Download this notebook from GitHub (right-click to download).


In [ ]:
import panel as pn
import numpy as np
import holoviews as hv

pn.extension()

This example demonstrates how to dynamically add and remove plots from a layout (in this case a Column) using the pop and append methods (requires a live Pytbon server):

In [ ]:
slider = pn.widgets.IntSlider(name='N', start=0, end=5)

column = pn.Column('This column will be populated with N Plots')

def set_plots(event):
    nplots = event.new-event.old
    for i in range(abs(nplots)):
        if nplots < 0:
            column.pop(len(column)-1)
        elif nplots > 0:
            column.append(hv.Scatter(np.random.randn(1000, 2)))
    
slider.param.watch(set_plots, 'value')
slider.value = 1

pn.Row(slider, column).servable()

Download this notebook from GitHub (right-click to download).