def test_hex_tiles_sum_value_aggregation(self): tiles = HexTiles([(0, 0, 1), (0.5, 0.5, 2), (-0.5, -0.5, 3), (-0.4, -0.4, 4)], vdims='z') binned = hex_binning(tiles, gridsize=3, aggregator=np.sum) expected = HexTiles([(0, 0, 1), (2, -1, 2), (-2, 1, 7)], kdims=[Dimension('x', range=(-0.5, 0.5)), Dimension('y', range=(-0.5, 0.5))], vdims='z') self.assertEqual(binned, expected)
def test_hex_tiles_count_aggregation(self): tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]) binned = hex_binning(tiles, gridsize=3) expected = HexTiles([(0, 0, 1), (2, -1, 1), (-2, 1, 2)], kdims=[Dimension('x', range=(-0.5, 0.5)), Dimension('y', range=(-0.5, 0.5))], vdims='Count') self.assertEqual(binned, expected)
def test_hex_tiles_hover_count(self): tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]).options(tools=['hover']) plot = list(bokeh_renderer.get_plot(tiles).subplots.values())[0] dims, opts = plot._hover_opts(tiles) self.assertEqual(dims, [Dimension('Count')]) self.assertEqual(opts, {})
def test_hex_tiles_gridsize_tuple(self): tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]).options(gridsize=(5, 10)) plot = list(bokeh_renderer.get_plot(tiles).subplots.values())[0] glyph = plot.handles['glyph'] self.assertEqual(glyph.size, 0.066666666666666666) self.assertEqual(glyph.aspect_scale, 0.5)
def test_hex_tiles_zero_min_count(self): tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]).options(min_count=0) plot = list(bokeh_renderer.get_plot(tiles).subplots.values())[0] cmapper = plot.handles['color_mapper'] self.assertEqual(cmapper.low, 0) self.assertEqual(plot.state.background_fill_color, cmapper.palette[0])
def test_hex_tiles_hover_weighted(self): tiles = HexTiles([(0, 0, 0.1), (0.5, 0.5, 0.2), (-0.5, -0.5, 0.3)], vdims='z').options(aggregator=np.mean) plot = list(bokeh_renderer.get_plot(tiles).subplots.values())[0] dims, opts = plot._hover_opts(tiles) self.assertEqual(dims, [Dimension('z')]) self.assertEqual(opts, {})
def hexbin(self, x, y, data=None): data = self.data if data is None else data if not x: x = data.columns[0] if not y: y = data.columns[1] z = self.kwds.get('C') opts = dict(plot=self._plot_opts, norm=self._norm_opts, style=self._style_opts) if 'reduce_function' in self.kwds: opts['plot']['aggregator'] = self.kwds['reduce_function'] if 'gridsize' in self.kwds: opts['plot']['gridsize'] = self.kwds['gridsize'] return HexTiles(data, [x, y], z or []).redim(**self._redim).opts(**opts)
def test_hex_tiles_opts(self): from holoviews.plotting.util import process_cmap tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]) plot = mpl_renderer.get_plot(tiles) args, style, _ = plot.get_data(tiles, {}, {}) self.assertEqual(args[0], tiles['x']) self.assertEqual(args[1], tiles['y']) self.assertEqual(args[2], np.ones(4)) cmap = style.pop('cmap') self.assertEqual( style, { 'reduce_C_function': np.sum, 'vmin': None, 'vmax': None, 'xscale': 'linear', 'yscale': 'linear', 'gridsize': 50, 'mincnt': None }) self.assertEqual(cmap.colors, process_cmap('viridis'))
def test_hex_tiles_only_nans(self): tiles = HexTiles([(np.NaN, 0), (1, np.NaN)]) plot = bokeh_renderer.get_plot(tiles) self.assertEqual(plot.handles['source'].data, {'q': [], 'r': []})
def test_hex_tiles_empty(self): tiles = HexTiles([]) plot = bokeh_renderer.get_plot(tiles) self.assertEqual(plot.handles['source'].data, {'q': [], 'r': []})
def test_hex_tile_scale_op(self): hextiles = HexTiles(np.random.randn(1000, 2)).options(scale='Count') plot = bokeh_renderer.get_plot(hextiles) glyph = plot.handles['glyph'] self.assertEqual(glyph.scale, {'field': 'scale'})
def test_hex_tile_alpha_op(self): hextiles = HexTiles(np.random.randn(1000, 2)).options(alpha='Count') plot = bokeh_renderer.get_plot(hextiles) glyph = plot.handles['glyph'] self.assertEqual(glyph.fill_alpha, {'field': 'alpha'})
def test_hex_tiles_empty(self): tiles = HexTiles([]) mpl_renderer.get_plot(tiles)
def test_hex_tiles_scale(self): tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]).options(size_index=2, gridsize=3) plot = list(bokeh_renderer.get_plot(tiles).subplots.values())[0] source = plot.handles['source'] self.assertEqual(source.data['scale'], np.array([0.45, 0.45, 0.9]))
def test_hex_tiles_empty(self): tiles = HexTiles([]) plot = list(bokeh_renderer.get_plot(tiles).subplots.values())[0] self.assertEqual(plot.handles['source'].data, {'q': [], 'r': []})
def test_hex_tiles_gridsize_tuple_flat_orientation(self): tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]).options(gridsize=(5, 10), orientation='flat') plot = bokeh_renderer.get_plot(tiles) glyph = plot.handles['glyph'] self.assertEqual(glyph.size, 0.13333333333333333) self.assertEqual(glyph.aspect_scale, 0.5)
def test_hex_tiles_scale_all_equal(self): tiles = HexTiles([(0, 0), (0.5, 0.5), (-0.5, -0.5), (-0.4, -0.4)]).options(size_index=2) plot = bokeh_renderer.get_plot(tiles) source = plot.handles['source'] self.assertEqual(source.data['scale'], np.array([0.9, 0.9, 0.9, 0.9]))
def test_hex_tile_line_width_op(self): hextiles = HexTiles(np.random.randn(1000, 2)).options(line_width='Count') plot = bokeh_renderer.get_plot(hextiles) glyph = plot.handles['glyph'] self.assertEqual(glyph.line_width, {'field': 'line_width'})