def test_batched_points_alpha_and_color(self): opts = { 'NdOverlay': dict(plot=dict(legend_limit=0)), 'Points': dict(style=dict(alpha=Cycle(values=[0.5, 1]))) } overlay = NdOverlay( {i: Points([(i, j) for j in range(2)]) for i in range(2)}).opts(opts) plot = bokeh_renderer.get_plot(overlay).subplots[()] alpha = np.array([0.5, 0.5, 1., 1.]) color = np.array(['#30a2da', '#30a2da', '#fc4f30', '#fc4f30'], dtype='<U7') self.assertEqual(plot.handles['source'].data['alpha'], alpha) self.assertEqual(plot.handles['source'].data['color'], color)
def test_batched_curve_subscribers_correctly_attached(self): posx = PointerX() opts = { 'NdOverlay': dict(plot=dict(legend_limit=0)), 'Curve': dict(style=dict(line_color=Cycle(values=['red', 'blue']))) } overlay = DynamicMap(lambda x: NdOverlay( {i: Curve([(i, j) for j in range(2)]) for i in range(2)}).opts(opts), kdims=[], streams=[posx]) plot = bokeh_renderer.get_plot(overlay) self.assertIn(plot.refresh, posx.subscribers) self.assertNotIn( list(plot.subplots.values())[0].refresh, posx.subscribers)
def test_batched_points_line_color_and_color(self): opts = { 'NdOverlay': dict(plot=dict(legend_limit=0)), 'Points': dict(style=dict(line_color=Cycle(values=['red', 'blue']))) } overlay = NdOverlay( {i: Points([(i, j) for j in range(2)]) for i in range(2)}).opts(opts) plot = bokeh_renderer.get_plot(overlay).subplots[()] line_color = np.array(['red', 'red', 'blue', 'blue']) fill_color = np.array(['#30a2da', '#30a2da', '#fc4f30', '#fc4f30'], dtype='<U7') self.assertEqual(plot.handles['source'].data['fill_color'], fill_color) self.assertEqual(plot.handles['source'].data['line_color'], line_color)
def test_batched_curve_subscribers_correctly_linked(self): # Checks if a stream callback is created to link batched plot # to the stream posx = PointerX() opts = { 'NdOverlay': dict(plot=dict(legend_limit=0)), 'Curve': dict(style=dict(line_color=Cycle(values=['red', 'blue']))) } overlay = DynamicMap(lambda x: NdOverlay( {i: Curve([(i, j) for j in range(2)]) for i in range(2)}).opts(opts), kdims=[], streams=[posx]) plot = bokeh_renderer.get_plot(overlay) self.assertEqual(len(Callback._callbacks), 1) key = list(Callback._callbacks.keys())[0] self.assertEqual(key, (id(plot.handles['plot']), id(PointerXCallback)))
def test_dynamic_subplot_remapping(self): # Checks that a plot is appropriately updated when reused def cb(X): return NdOverlay( {i: Curve(np.arange(10) + i) for i in range(X - 2, X)}) dmap = DynamicMap(cb, kdims=['X']).redim.range(X=(1, 10)) plot = bokeh_renderer.get_plot(dmap) plot.update((3, )) legend_labels = [item.label for item in plot.state.legend[0].items] self.assertEqual(legend_labels, [{'value': '1'}, {'value': '2'}]) colors = Cycle().values for i, (subplot, color) in enumerate(zip(plot.subplots.values(), colors[3:])): self.assertEqual(subplot.handles['glyph'].line_color, color) self.assertEqual(subplot.cyclic_index, i + 3) self.assertEqual(list(subplot.overlay_dims.values()), [i + 1])
def test_style_opts_cycle_function(self): # Explicitly compare because list of arrays do not compare correctly import numpy as np np.random.seed(42) line = "Curve (color=Cycle(values=list(np.random.rand(3,3))))" options = OptsSpec.parse(line, {'np': np, 'Cycle': Cycle}) self.assertTrue('Curve' in options) self.assertTrue('style' in options['Curve']) self.assertTrue('color' in options['Curve']['style'].kwargs) self.assertTrue( isinstance(options['Curve']['style'].kwargs['color'], Cycle)) values = np.array([[0.37454012, 0.95071431, 0.73199394], [0.59865848, 0.15601864, 0.15599452], [0.05808361, 0.86617615, 0.60111501]]) expected = { 'Curve': { 'style': Options(color=Cycle(values=list(values))) } } self.assertEqual( np.array(options['Curve']['style'].kwargs['color'].values), values)
def test_cycle_init(self): Cycle(values=['a', 'b', 'c']) Cycle(values=[1, 2, 3])
def test_cyclic_property_true(self): cycle1 = Cycle(values=['a', 'b', 'c']) opts = Options('test', one=cycle1, two='two') self.assertEqual(opts.cyclic, True)
def test_process_cmap_cycle(self): colors = process_cmap(Cycle(values=['#ffffff', '#959595', '#000000']), 4) self.assertEqual(colors, ['#ffffff', '#959595', '#000000', '#ffffff'])
def __init__(self, data, x, y, kind=None, by=None, use_index=True, group_label='Variable', value_label='value', backlog=1000, persist=False, use_dask=False, crs=None, fields={}, groupby=None, dynamic=True, width=700, height=300, shared_axes=True, grid=False, legend=True, rot=None, title=None, xlim=None, ylim=None, clim=None, xticks=None, yticks=None, logx=False, logy=False, loglog=False, hover=True, subplots=False, label=None, invert=False, stacked=False, colorbar=None, fontsize=None, colormap=None, datashade=False, rasterize=False, row=None, col=None, figsize=None, debug=False, xaxis=True, yaxis=True, framewise=True, aggregator=None, projection=None, global_extent=False, geo=False, precompute=False, flip_xaxis=False, flip_yaxis=False, dynspread=False, hover_cols=[], x_sampling=None, y_sampling=None, **kwds): # Process data and related options self._process_data(kind, data, x, y, by, groupby, row, col, use_dask, persist, backlog, label, value_label, hover_cols, kwds) self.use_index = use_index self.value_label = value_label self.group_label = group_label self.dynamic = dynamic self.geo = geo or crs or global_extent or projection self.crs = process_crs(crs) if self.geo else None self.row = row self.col = col # Operations self.datashade = datashade self.rasterize = rasterize self.dynspread = dynspread self.aggregator = aggregator self.precompute = precompute self.x_sampling = x_sampling self.y_sampling = y_sampling # By type self.subplots = subplots self._by_type = NdLayout if subplots else NdOverlay # Process options style_opts, plot_opts, kwds = self._process_style(colormap, kwds) self.stacked = stacked self.invert = invert plot_opts['logx'] = logx or loglog plot_opts['logy'] = logy or loglog plot_opts['show_grid'] = grid plot_opts['shared_axes'] = shared_axes plot_opts['show_legend'] = legend if xticks: plot_opts['xticks'] = xticks if yticks: plot_opts['yticks'] = yticks if not xaxis: plot_opts['xaxis'] = None if not yaxis: plot_opts['yaxis'] = None if flip_xaxis: plot_opts['invert_xaxis'] = True if flip_yaxis: plot_opts['invert_yaxis'] = True if width: plot_opts['width'] = width if height: plot_opts['height'] = height if fontsize: plot_opts['fontsize'] = fontsize if isinstance(colorbar, bool): plot_opts['colorbar'] = colorbar elif self.kind in self._colorbar_types: plot_opts['colorbar'] = True if invert: plot_opts['invert_axes'] = kind != 'barh' if rot: axis = 'yrotation' if invert else 'xrotation' plot_opts[axis] = rot if hover: plot_opts['tools'] = ['hover'] if self.crs and global_extent: plot_opts['global_extent'] = global_extent if projection: plot_opts['projection'] = process_crs(projection) plot_opts['legend_position'] = 'right' if title is not None: plot_opts['title_format'] = title self._plot_opts = plot_opts options = Store.options(backend='bokeh') el_type = self._kind_mapping[self.kind].__name__ style = options[el_type].groups['style'] cycled_opts = [ k for k, v in style.kwargs.items() if isinstance(v, Cycle) ] for opt in cycled_opts: color = style_opts.get('color', None) if color is None: color = process_cmap(colormap or 'Category10', categorical=True) style_opts[opt] = Cycle( values=color) if isinstance(color, list) else color self._style_opts = style_opts self._norm_opts = {'framewise': framewise, 'axiswise': not shared_axes} self.kwds = kwds # Process dimensions and labels self.label = label self._relabel = {'label': label} if label else {} self._dim_ranges = { 'x': xlim or (None, None), 'y': ylim or (None, None), 'c': clim or (None, None) } self._redim = fields # High-level options self._validate_kwds(kwds) if debug: kwds = dict(x=self.x, y=self.y, by=self.by, kind=self.kind, groupby=self.groupby) self.warning('Plotting {kind} plot with parameters x: {x}, ' 'y: {y}, by: {by}, groupby: {groupby}'.format(**kwds))
def test_cycle_init(self): cycle1 = Cycle(['a', 'b', 'c']) cycle2 = Cycle([1, 2, 3])