import numpy as np import pandas as pd import holoviews as hv from holoviews import dim, opts hv.extension('bokeh') img = hv.Image(np.random.rand(10, 10)) fig = hv.render(img) print('Figure: ', fig) print('Renderers: ', fig.renderers[-1].glyph) violin = hv.Violin(np.random.randn(100)) hv.output(violin, fig='png') from holoviews.plotting.bokeh.styles import (line_properties, fill_properties, text_properties) print(""" Line properties: %s\n Fill properties: %s\n Text properties: %s """ % (line_properties, fill_properties, text_properties)) curve_opts = opts.Curve(line_width=10, line_color='indianred', line_dash='dotted', line_alpha=0.5) point_opts = opts.Points(fill_color='#00AA00', fill_alpha=0.5, line_width=1, line_color='black', size=5) text_opts = opts.Text(text_align='center', text_baseline='middle', text_color='gray', text_font='Arial') xs = np.linspace(0, np.pi*4, 100) data = (xs, np.sin(xs)) (hv.Curve(data) + hv.Points(data) + hv.Text(6, 0, 'Here is some text')).opts( curve_opts, point_opts, text_opts) points_a = hv.Points(data) points_b = hv.Points(data) points_a.opts(width=300, height=300) + points_b.opts(width=600, height=300) xs = ys = np.arange(10) yy, xx = np.meshgrid(xs, ys) zz = xx*yy img = hv.Image(np.random.rand(100, 100)) points_a.opts(frame_width=200, frame_height=200) +\ img.opts(frame_width=200, frame_height=200, colorbar=True, axiswise=True) xs = np.linspace(0, 10) ys = np.linspace(0, 5) img = hv.Image((xs, ys, xs[:, np.newaxis]*np.sin(ys*4))) (img.options(aspect='equal').relabel('aspect=\'equal\'') + img.options(aspect='square', colorbar=True, frame_width=300).relabel('aspect=\'square\'') + img.options(aspect=2).relabel('aspect=2') + img.options(data_aspect=2, frame_width=300).relabel('data_aspect=2')).cols(2) hv.Points(data).opts(height=200, responsive=True, title='stretch width') img.opts(data_aspect=0.5, responsive=True, title='scale both') points = hv.Points(data).opts(axiswise=True) img = hv.Image((xs, ys, xs[:, np.newaxis]*np.sin(ys*4))) img + points.opts(height=200, align='end') (img.opts(axiswise=True, width=200, align='center') + points).cols(1) grid_style = {'grid_line_color': 'black', 'grid_line_width': 1.5, 'ygrid_bounds': (0.3, 0.7), 'minor_xgrid_line_color': 'lightgray', 'xgrid_line_dash': [4, 4]} hv.Points(np.random.rand(10, 2)).opts(gridstyle=grid_style, show_grid=True, size=5, width=600) x,y = np.mgrid[-50:51, -50:51] * 0.1 img = hv.Image(np.sin(x**2+y**2), bounds=(-1,-1,1,1)) (img.relabel('Image') * img.sample(x=0).relabel('Cross-section')).opts(tabs=True) hv.NdOverlay({i: hv.Histogram(np.histogram(np.random.randn(100)+i*2)) for i in range(5)}).opts( 'Histogram', width=600, alpha=0.8, muted_fill_alpha=0.1) points = hv.Points(np.random.randn(500,2)) points.hist(num_bins=51, dimension=['x','y']) img.hist(num_bins=100, dimension=['x', 'y'], weight_dimension='z', mean_weighted=True) +\ img.hist(dimension='z') (hv.Curve([1, 2, 3]).opts(toolbar='above') + hv.Curve([1, 2, 3]).opts(toolbar=None)).opts(merge_tools=False) error = np.random.rand(100, 3) heatmap_data = {(chr(65+i), chr(97+j)):i*j for i in range(5) for j in range(5) if i!=j} data = [np.random.normal() for i in range(10000)] hist = np.histogram(data, 20) points = hv.Points(error) heatmap = hv.HeatMap(heatmap_data).sort() histogram = hv.Histogram(hist) image = hv.Image(np.random.rand(50,50)) (points + heatmap + histogram + image).opts( opts.Points(tools=['hover'], size=5), opts.HeatMap(tools=['hover']), opts.Image(tools=['hover']), opts.Histogram(tools=['hover']), opts.Layout(shared_axes=False)).cols(2) error = np.random.rand(100, 3) heatmap_data = {(chr(65+i), chr(97+j)):i*j for i in range(5) for j in range(5) if i!=j} data = [np.random.normal() for i in range(10000)] hist = np.histogram(data, 20) points = hv.Points(error) heatmap = hv.HeatMap(heatmap_data).sort() histogram = hv.Histogram(hist) image = hv.Image(np.random.rand(50,50)) (points + heatmap + histogram + image).opts( opts.Points(tools=['hline'], size=5), opts.HeatMap(tools=['hover']), opts.Image(tools=['vline']), opts.Histogram(tools=['hover']), opts.Layout(shared_axes=False)).cols(2) from bokeh.models import HoverTool from bokeh.sampledata.periodic_table import elements points = hv.Points( elements, ['electronegativity', 'density'], ['name', 'symbol', 'metal', 'CPK', 'atomic radius'] ).sort('metal') tooltips = [ ('Name', '@name'), ('Symbol', '@symbol'), ('CPK', '$color[hex, swatch]:CPK') ] hover = HoverTool(tooltips=tooltips) points.opts( tools=[hover], color='metal', cmap='Category20', line_color='black', size=dim('atomic radius')/10, width=600, height=400, show_grid=True, title='Chemical Elements by Type (scaled by atomic radius)') hv.Points(error).opts( color='blue', nonselection_color='red', size=10, tools=['box_select', 'lasso_select', 'tap']) macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\t') (hv.Scatter(macro_df, 'year', 'gdp') + hv.Scatter(macro_df, 'gdp', 'unem')).opts( opts.Scatter(tools=['box_select', 'lasso_select']), opts.Layout(shared_axes=True, shared_datasource=True)) table = hv.Dataset(macro_df, kdims=['year', 'country']) matrix = hv.operation.gridmatrix(table.groupby('country')) matrix.select(country=['West Germany', 'United Kingdom', 'United States']).opts( opts.Scatter(tools=['box_select', 'lasso_select', 'hover'], border=0)) path = hv.Path([]) freehand = hv.streams.FreehandDraw(source=path, num_objects=3) path.opts( opts.Path(active_tools=['freehand_draw'], height=400, line_width=10, width=400)) freehand.element.split() from bokeh.themes.theme import Theme theme = Theme( json={ 'attrs' : { 'Figure' : { 'background_fill_color': '#2F2F2F', 'border_fill_color': '#2F2F2F', 'outline_line_color': '#444444', }, 'Grid': { 'grid_line_dash': [6, 4], 'grid_line_alpha': .3, }, 'Axis': { 'major_label_text_color': 'white', 'axis_label_text_color': 'white', 'major_tick_line_color': 'white', 'minor_tick_line_color': 'white', 'axis_line_color': "white" } } }) hv.renderer('bokeh').theme = theme xs = np.linspace(0, np.pi*4, 100) hv.Curve((xs, np.sin(xs)), label='foo').opts(bgcolor='grey') hv.renderer('bokeh').theme = 'light_minimal' xs = np.linspace(0, np.pi*4, 100) hv.Curve((xs, np.sin(xs)), label='foo')