import numpy as np import pandas as pd import holoviews as hv hv.extension('bokeh') from holoviews.plotting.bokeh.element 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 = dict(line_width=10, line_color='indianred', line_dash='dotted', line_alpha=0.5) point_opts = dict(fill_color='#00AA00', fill_alpha=0.5, line_width=1, line_color='black', size=5) text_opts = dict(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).options(**curve_opts) + hv.Points(data).options(**point_opts) + hv.Text(6, 0, 'Here is some text').options(**text_opts)) %%opts Points.A [width=300 height=300] Points.B [width=600 height=300] hv.Points(data, group='A') + hv.Points(data, group='B') points = hv.Points(np.exp(xs)) axes_opts = [('Plain', {}), ('Log', {'logy': True}), ('None', {'yaxis': None}), ('Rotate', {'xrotation': 90}), ('N Ticks', {'xticks': 3}), ('List Ticks', {'xticks': [0, 20, 50, 90]})] hv.Layout([points.relabel(group=group).options(**opts) for group, opts in axes_opts]).cols(3) %%opts Overlay [width=600 legend_position='top_left'] Curve (muted_alpha=0.5 muted_color='black') try: import bokeh.sampledata.stocks except: import bokeh.sampledata bokeh.sampledata.download() from bokeh.sampledata.stocks import GOOG, AAPL goog_dates = np.array(GOOG['date'], dtype=np.datetime64) aapl_dates = np.array(AAPL['date'], dtype=np.datetime64) hv.Curve((goog_dates, GOOG['adj_close']), 'Date', 'Stock Index', label='Google') *\ hv.Curve((aapl_dates, AAPL['adj_close']), 'Date', 'Stock Index', label='Apple') %%opts Points [size_index='z' tools=['hover']] HeatMap [toolbar='above' tools=['hover']] points = hv.Points([(chr(i+65), chr(j+65), i*j) for i in range(10) for j in range(10)], vdims='z') hv.HeatMap(points) * points %%opts Overlay [show_legend=False height=400 width=600] %%opts ErrorBars (line_width=5) Scatter [jitter=0.2] (alpha=0.2 size=6) overlay = hv.NdOverlay({group: hv.Scatter(([group]*100, np.random.randn(100)*(i+1)+i)) for i, group in enumerate(['A', 'B', 'C', 'D', 'E'])}) errorbars = hv.ErrorBars([(k, el.reduce(function=np.mean), el.reduce(function=np.std)) for k, el in overlay.items()]) global_mean = hv.Text('A', 12, 'Global mean: %.3f' % overlay.dimension_values('y').mean(), halign='left') errorbars * overlay * hv.Curve(errorbars) * global_mean 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)).options(gridstyle=grid_style, show_grid=True, size=5, width=600) %%opts Overlay [tabs=True] Curve Image [width=400 height=400] 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 Histogram [width=600] (alpha=0.8 muted_fill_alpha=0.1) hv.NdOverlay({i: hv.Histogram(np.histogram(np.random.randn(100)+i*2)) for i in range(5)}) 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') hmap = hv.HoloMap({phase: img.clone(np.sin(x**2+y**2+phase)) for phase in np.linspace(0, np.pi*2, 6)}, kdims='Phase') hmap.hist(num_bins=100, dimension=['x', 'y'], weight_dimension='z', mean_weighted=True) %%opts Points [tools=['hover']] (size=5) HeatMap [tools=['hover']] %%opts Histogram [tools=['hover']] Layout [shared_axes=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) hv.Points(error) + hv.HeatMap(heatmap_data).sort() + hv.Histogram(hist) %%opts Points [tools=['box_select', 'lasso_select', 'tap']] (size=10 nonselection_color='red' color='blue') hv.Points(error) macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\t') %%opts Scatter [tools=['box_select', 'lasso_select']] Layout [shared_axes=True shared_datasource=True] hv.Scatter(macro_df, 'year', 'gdp') +\ hv.Scatter(macro_df, 'gdp', 'unem') %%opts Scatter [tools=['box_select', 'lasso_select', 'hover'] border=0] Histogram {+axiswise} table = hv.Table(macro_df, kdims=['year', 'country']) matrix = hv.operation.gridmatrix(table.groupby('country')) matrix.select(country=['West Germany', 'United Kingdom', 'United States']) 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 %%opts Curve [bgcolor='grey'] xs = np.linspace(0, np.pi*4, 100) hv.Curve((xs, np.sin(xs)), label='foo')