Code
import holoviews as hv
import panel as pn
"bokeh") # same as hvplot.extension("bokeh")
hv.extension(="material") pn.extension(design
This guide shows you how to use the HoloViz ecosystem with Quarto {python}
code blocks to create live and interactive documents.
For hvPlot, HoloViews or Panel to work with Quarto, you must remember to run the the .extension
function to include the relevant css and javascript files.
import holoviews as hv
import panel as pn
"bokeh") # same as hvplot.extension("bokeh")
hv.extension(="material") pn.extension(design
This is a hvPlot plot embedded in a Quarto document.
import hvplot.pandas
import pandas as pd
=pd.DataFrame({"x": [1,2,3], "y": [1,3,2]})
df
='x', y='y', height=400, responsive=True) df.hvplot.line(x
You can make widgets created with a groupby
argument interactive, if you add the dynamic=False
arguments
import hvplot.pandas
import numpy as np
import pandas as pd
= [0.5, 0.75, 1.0, 1.25]
frequencies
def sine_curve(phase, freq):
= np.arange(100)
xvals = np.sin(phase+freq*xvals)
yvals return pd.DataFrame({'x': xvals, 'y': yvals, 'phase': phase, 'freq': freq}, columns=['x', 'y', 'phase', 'freq'])
= pd.concat([sine_curve(0, f) for f in frequencies])
df
'x', 'y', groupby='freq', dynamic=False, responsive=True, height=400) df.hvplot.line(
Please note that changing the widget_location
currently does not work. See hvPlot #1241.
import holoviews as hv
import pandas as pd
=pd.DataFrame({"x": [1,2,3], "y": [1,3,2]})
df
="x", vdims="y").opts(height=400, responsive=True) hv.Curve(df, kdims
You can browse through a collection (dictionary) of plots via HoloMap.
import numpy as np
import holoviews as hv
# hv.output(widget_location="top_left")
def sine_curve(phase, freq):
= [0.1* i for i in range(100)]
xvals return hv.Curve((xvals, [np.sin(phase+freq*x) for x in xvals]))
= [0.5, 0.75, 1.0, 1.25]
frequencies = [0, np.pi/2, np.pi, 3*np.pi/2]
phases
= {(p,f):sine_curve(p,f) for p in phases for f in frequencies}
curve_dict_2D
=['phase', 'frequency']).opts(responsive=True, height=300) hv.HoloMap(curve_dict_2D, kdims
You can change the default widget_location
via hv.output(widget_location="top_left")
You may display HoloMaps as gif
or mp4
. See hv.output
settings.
import panel as pn
= pn.widgets.IntSlider(name="Select a value", value=2, start=0, end=10)
slider
pn.Column("You selected: {}").format(slider),
pn.rx( )
Please note that the output above is not live and interactive. When you drag the slider nothing happens.
For simple apps with a limited amount of state it is possible to embed the state. See the Panel how-to embed state guide.
import panel as pn
= pn.widgets.IntSlider(name="Select a value", value=2, start=0, end=10)
slider
pn.Column("You selected: {}").format(slider),
pn.rx(=11, max_opts=11) ).embed(max_states
Now the text updates when you drag the slider above.
You may also Link Plot Parameters in Javascript.
import hvplot.pandas
import pandas as pd
import panel as pn
=pd.DataFrame({"x": [1,2,3], "y": [1,3,2]})
df= df.hvplot.line(x='x', y='y', height=400, responsive=True)
plot
= pn.widgets.FloatSlider(name="Line Width", start=3, end=10, step=0.1)
width_slider ="glyph.line_width")
width_slider.jslink(plot, value pn.Column(width_slider, plot)
For more on Javascript linking check out the Link Parameters Guides.
Please note that hvPlot and HoloViews plots like HoloMaps with widgets currently do not work inside Panel Layouts in Quarto documents. See Panel #6131.