import numpy as np import holoviews as hv from holoviews import dim, opts hv.extension('bokeh') data = { 'x values': [0, 1, 0.5], 'y values': [1, 0, 0.5], 'alpha': [0.5, 1, 0.3], 'color': ['red', 'blue', 'green'], 'marker': ['circle', 'triangle', 'diamond'], 'size': [15, 25, 40] } opts.defaults(opts.Points(size=8, line_color='black')) hv.Points(data, kdims=['x values','y values'] , vdims=['alpha', 'color', 'marker', 'size']).opts( alpha='alpha', color='color', marker='marker', size='size') points = hv.Points(np.random.rand(400, 4)) bins = [0, .25, 0.5, .75, 1] labels = ['circle', 'triangle', 'diamond', 'square'] layout = hv.Layout([ points.relabel('Alpha' ).opts(alpha =dim('x').norm()), points.relabel('Angle' ).opts(angle =dim('x').norm()*360, marker='dash'), points.relabel('Color' ).opts(color =dim('x')), points.relabel('Marker').opts(marker=dim('x').bin(bins, labels)), points.relabel('Size' ).opts(size =dim('x')*10) ]) layout.opts(opts.Points(width=250, height=250, xaxis=None, yaxis=None)).cols(5) from holoviews import dim ds = hv.Dataset(np.random.rand(10, 4)*10, ['x', 'y'], ['alpha', 'size']) dim('alpha').apply(ds) math_op = (dim('alpha')-5).min() math_op math_op.apply(ds) dim('alpha').norm().apply(ds) bin_op = dim('alpha').bin([0, 5, 10]) bin_op.apply(ds) dim('alpha').bin([0, 5, 10], ['Bin 1', 'Bin 2']).apply(ds) dim(bin_op).categorize({2.5: 'circle', 7.5: 'square'}).apply(ds) points.opts( alpha =(dim('x')+0.2).norm(), angle =np.sin(dim('y'))*360, color =dim('x')**2, marker=dim('y').bin(bins, labels), size =dim('x')**dim('y')*20, width=500, height=500) def format_list(l): print(' '.join(sorted([k for k in l if not k.endswith('_r')]))) format_list(hv.plotting.list_cmaps()) ls = np.linspace(0, 10, 400) xx, yy = np.meshgrid(ls, ls) bounds=(-1,-1,1,1) # Coordinate system: (left, bottom, right, top) img = hv.Image(np.sin(xx)*np.cos(yy), bounds=bounds).opts(colorbar=True, width=400) img.relabel('PiYG').opts(cmap='PiYG') + img.relabel('PiYG_r').opts(cmap='PiYG_r') img.relabel('Listed colors').opts(cmap=['#0000ff', '#8888ff', '#ffffff', '#ff8888', '#ff0000'], colorbar=True, width=400) img.relabel('5 color levels').opts(cmap='PiYG', color_levels=5) + img.relabel('11 color levels').opts(cmap='PiYG', color_levels=11) polygons = hv.Polygons([{('x', 'y'): hv.Ellipse(0, 0, (i, i)).array(), 'z': i} for i in range(1, 10)[::-1]], vdims='z') polygons.opts(color='z', colorbar=True, width=380) categorical_points = hv.Points((np.random.rand(100), np.random.rand(100), np.random.choice(list('ABCD'), 100)), vdims='Category') categorical_points.sort('Category').opts( color='Category', cmap='Category20', size=8, legend_position='left', width=500) explicit_mapping = {'A': 'blue', 'B': 'red', 'C': 'green', 'D': 'purple'} categorical_points.sort('Category').opts(color='Category', cmap=explicit_mapping, size=8) levels = [0, 38, 73, 95, 110, 130, 156, 999] colors = ['#5ebaff', '#00faf4', '#ffffcc', '#ffe775', '#ffc140', '#ff8f20', '#ff6060'] path = [ (-75.1, 23.1, 0), (-76.2, 23.8, 0), (-76.9, 25.4, 0), (-78.4, 26.1, 39), (-79.6, 26.2, 39), (-80.3, 25.9, 39), (-82.0, 25.1, 74), (-83.3, 24.6, 74), (-84.7, 24.4, 96), (-85.9, 24.8, 111), (-87.7, 25.7, 111), (-89.2, 27.2, 131), (-89.6, 29.3, 156), (-89.6, 30.2, 156), (-89.1, 32.6, 131), (-88.0, 35.6, 111), (-85.3, 38.6, 96) ] hv.Path([path], vdims='Wind Speed').opts( color='Wind Speed', color_levels=levels, cmap=colors, line_width=8, colorbar=True, width=450 ) clipping = {'min': 'red', 'max': 'green', 'NaN': 'gray'} options = dict(cmap='Blues', colorbar=True, width=300, height=230, axiswise=True) arr = np.sin(xx)*np.cos(yy) arr[:190, :127] = np.nan original = hv.Image(arr, bounds=bounds).opts(**options) colored = original.opts(clipping_colors=clipping, clone=True) clipped = colored.redim.range(z=(0, 0.9)) original + colored + clipped np.random.seed(42) data = np.random.normal(loc=3, scale=0.3, size=(100,100)) print("Mean value of random samples is {mean:.3f}, ".format(mean=np.mean(data)) + "which is much lower\nthan the black square in the center (value 100).") data[45:55,45:55] = 100 imopts=dict(colorbar=True, xaxis='bare', yaxis='bare', height=160, width=200) pattern = hv.Image(data) ( pattern.options(cnorm='linear', title='linear', **imopts) + pattern.options(cnorm='log', title='log', **imopts) + pattern.options(cnorm='eq_hist', title='eq_hist', **imopts)) points = ( hv.Points(np.random.randn(50, 2) ) * hv.Points(np.random.randn(50, 2) + 1 ) * hv.Points(np.random.randn(50, 2) * 0.5) ) color_cycle = hv.Cycle(['red', 'green', 'blue']) points + points.opts(opts.Points(color=color_cycle), clone=True) format_list(hv.Cycle.default_cycles.keys()) xs = np.linspace(0, np.pi*2) curves = hv.Overlay([hv.Curve(np.sin(xs+p)) for p in np.linspace(0, np.pi, 10)]) curves.opts(opts.Curve(color=hv.Cycle('Category20'), width=600)) color = hv.Cycle(['#30a2da', '#fc4f30', '#e5ae38']) markers = hv.Cycle(['x', '^', '+']) sizes = hv.Cycle([10, 5]) points.opts(opts.Points(line_color=color, marker=markers, size=sizes)) format_list(hv.Palette.colormaps.keys()) ellipses = hv.Overlay([hv.Ellipse(0, 0, s) for s in range(6)]) ellipses.relabel('Palette').opts(opts.Ellipse(color=hv.Palette('Spectral'), line_width=5), clone=True) +\ ellipses.relabel('Cycle' ).opts(opts.Ellipse(color=hv.Cycle( 'Spectral'), line_width=5), clone=True)