def setUp(self): if 'bokeh' not in Store.renderers: raise SkipTest("Bokeh required to test widgets") self.image1 = Image(np.array([[0, 1], [2, 3]]), label='Image1') self.image2 = Image(np.array([[1, 0], [4, -2]]), label='Image2') self.map1 = HoloMap({1: self.image1, 2: self.image2}, label='TestMap') self.renderer = BokehRenderer.instance()
def test_render_to_png(self): if bokeh_version < str('0.12.6'): raise SkipTest('Bokeh static png rendering requires bokeh>=0.12.6') curve = Curve([]) renderer = BokehRenderer.instance(fig='png') png, info = renderer(curve) self.assertIsInstance(png, bytes) self.assertEqual(info['file-ext'], 'png')
def test_render_to_png(self): curve = Curve([]) renderer = BokehRenderer.instance(fig='png') try: png, info = renderer(curve) except RuntimeError: raise SkipTest("Test requires selenium") self.assertIsInstance(png, bytes) self.assertEqual(info['file-ext'], 'png')
def setUp(self): if 'bokeh' not in Store.renderers: raise SkipTest("Bokeh required to test widgets") self.image1 = Image(np.array([[0,1],[2,3]]), label='Image1') self.image2 = Image(np.array([[1,0],[4,-2]]), label='Image2') self.map1 = HoloMap({1:self.image1, 2:self.image2}, label='TestMap') self.renderer = BokehRenderer.instance() self.nbcontext = Renderer.notebook_context Renderer.notebook_context = False
def setUp(self): if 'bokeh' not in Store.renderers and pn is not None: raise SkipTest("Bokeh and Panel required to test 'bokeh' renderer") self.image1 = Image(np.array([[0, 1], [2, 3]]), label='Image1') self.image2 = Image(np.array([[1, 0], [4, -2]]), label='Image2') self.map1 = HoloMap({1: self.image1, 2: self.image2}, label='TestMap') self.renderer = BokehRenderer.instance() self.nbcontext = Renderer.notebook_context self.comm_manager = Renderer.comm_manager with param.logging_level('ERROR'): Renderer.notebook_context = False Renderer.comm_manager = CommManager
def test_theme_rendering(self): theme = Theme( json={'attrs': { 'Figure': { 'outline_line_color': '#444444' } }}) renderer = BokehRenderer.instance(fig='png') renderer.theme = theme plot = renderer.get_plot(Curve([])) renderer(plot) self.assertEqual(plot.state.outline_line_color, '#444444')
def test_render_to_png(self): curve = Curve([]) renderer = BokehRenderer.instance(fig='png') png, info = renderer(curve) self.assertIsInstance(png, bytes) self.assertEqual(info['file-ext'], 'png')
def get_fractal(x_range, y_range): (x0, x1), (y0, y1) = x_range, y_range image = np.zeros((600, 600), dtype=np.uint8) return hv.Image(create_fractal(x0, x1, -y1, -y0, image, 200), bounds=(x0, y0, x1, y1)) # Define stream linked to axis XY-range range_stream = RangeXY(x_range=(-1., 1.), y_range=(-1., 1.)) # Create DynamicMap to compute fractal per zoom range and # adjoin a logarithmic histogram dmap = hv.DynamicMap(get_fractal, label='Manderbrot Explorer', streams=[range_stream]).hist(log=True) # Define styling options options = hv.Store.options('bokeh') options.Image = { 'style': Options(cmap='fire'), 'plot': Options(logz=True, height=600, width=600, xaxis=None, yaxis=None) } options.Histogram = { 'norm': Options(framewise=True), 'plot': Options(logy=True, width=200) } doc = BokehRenderer.server_doc(dmap) doc.title = 'Mandelbrot Explorer'
# Update the holoviews plot by calling update with the new year. def slider_update(attrname, old, new): hvplot.update((new, )) def animate(): if button.label == '► Play': button.label = '❚❚ Pause' doc.add_periodic_callback(animate_update, 200) else: button.label = '► Play' doc.remove_periodic_callback(animate_update) start, end = ds.range('Year') slider = Slider(start=start, end=end, value=start, step=1, title="Year") slider.on_change('value', slider_update) button = Button(label='► Play', width=60) button.on_click(animate) # Get HoloViews plot and attach document doc = curdoc() hvplot = BokehRenderer.get_plot(hvgapminder, doc) # Make a bokeh layout and add it as the Document root plot = layout([[hvplot.state], [slider, button]], sizing_mode='fixed') doc.add_root(plot)
return image def get_fractal(x_range, y_range): (x0, x1), (y0, y1) = x_range, y_range image = np.zeros((600, 600), dtype=np.uint8) return hv.Image(create_fractal(x0, x1, -y1, -y0, image, 200), bounds=(x0, y0, x1, y1)) # Define stream linked to axis XY-range range_stream = RangeXY(x_range=(-1., 1.), y_range=(-1., 1.)) # Create DynamicMap to compute fractal per zoom range and # adjoin a logarithmic histogram dmap = hv.DynamicMap(get_fractal, label='Manderbrot Explorer', streams=[range_stream]).hist(log=True) # Define styling options options = hv.Store.options('bokeh') options.Image = { 'style': Options(cmap='fire'), 'plot' : Options(logz=True, height=600, width=600, xaxis=None, yaxis=None) } options.Histogram = { 'norm': Options(framewise=True), 'plot': Options(logy=True, width=200) } doc = BokehRenderer.server_doc(dmap) doc.title = 'Mandelbrot Explorer'
def gapminder_plot(doc): # Apply dimension labels and ranges kdims = ['Fertility', 'Life expectancy'] vdims = ['Country', 'Population', 'Group'] dimensions = { 'Fertility': dict(label='Children per woman (total fertility)', range=(0, 10)), 'Life expectancy': dict(label='Life expectancy at birth (years)', range=(15, 100)), 'Population': ('population', 'Population') } # Create Points plotting fertility vs life expectancy indexed by Year gapminder_ds = ds.redim(**dimensions).to(hv.Points, kdims, vdims, 'Year') # Define annotations text = gapminder_ds.clone({ yr: hv.Text(1.2, 25, str(int(yr)), fontsize=30) for yr in gapminder_ds.keys() }) # Define options opts = { 'plot': dict(width=950, height=450, tools=['hover'], size_index='Population', color_index='Group', size_fn=np.sqrt, title_format="{label}"), 'style': dict(cmap='Set1', size=0.3, line_color='black', alpha=0.6) } text_opts = {'style': dict(text_font_size='52pt', text_color='lightgray')} # Combine Points and Text hvgapminder = (gapminder_ds({'Points': opts}) * text({'Text': text_opts})).relabel('Gapminder Demo') # Define custom widgets def animate_update(): year = slider.value + 1 if year > end: year = start slider.value = year # Update the holoviews plot by calling update with the new year. def slider_update(attrname, old, new): hvplot.update((new, )) def animate(): if button.label == '► Play': button.label = '❚❚ Pause' doc.add_periodic_callback(animate_update, 200) else: button.label = '► Play' doc.remove_periodic_callback(animate_update) start, end = ds.range('Year') slider = Slider(start=start, end=end, value=start, step=1, title="Year") slider.on_change('value', slider_update) button = Button(label='► Play', width=60) button.on_click(animate) # Get HoloViews plot hvplot = BokehRenderer.get_plot(hvgapminder, doc) # Make a bokeh layout and add it as the Document root plot = layout([[hvplot.state], [slider, button]], sizing_mode='fixed') doc.add_root(plot) return doc
if year > end: year = start slider.value = year # Update the holoviews plot by calling update with the new year. def slider_update(attrname, old, new): hvplot.update((new,)) def animate(): if button.label == '► Play': button.label = '❚❚ Pause' doc.add_periodic_callback(animate_update, 200) else: button.label = '► Play' doc.remove_periodic_callback(animate_update) start, end = ds.range('Year') slider = Slider(start=start, end=end, value=start, step=1, title="Year") slider.on_change('value', slider_update) button = Button(label='► Play', width=60) button.on_click(animate) # Get HoloViews plot and attach document doc = curdoc() hvplot = BokehRenderer.get_plot(hvgapminder, doc) # Make a bokeh layout and add it as the Document root plot = layout([[hvplot.state], [slider, button]], sizing_mode='fixed') doc.add_root(plot)