def test_heatmap_hover_ensure_kdims_sanitized(self): hm = HeatMap([(1, 1, 1), (2, 2, 0)], kdims=['x with space', 'y with $pecial symbol']) hm = hm.opts(tools=['hover']) self._test_hover_info( hm, [('x with space', '@{x_with_space}'), ('y with $pecial symbol', '@{y_with_pecial_symbol}'), ('z', '@{z}')])
def test_heatmap_custom_string_tooltip_hover(self): tooltips = "<div><h1>Test</h1></div>" custom_hover = HoverTool(tooltips=tooltips) hm = HeatMap([(1,1,1), (2,2,0)], kdims=['x with space', 'y with $pecial symbol']) hm = hm.options(tools=[custom_hover]) plot = bokeh_renderer.get_plot(hm) hover = plot.handles['hover'] self.assertEqual(hover.tooltips, tooltips) self.assertEqual(hover.renderers, [plot.handles['glyph_renderer']])
def test_heatmap_invert_axes(self): arr = np.array([[0, 1, 2], [3, 4, 5]]) hm = HeatMap(Image(arr)).opts(plot=dict(invert_axes=True)) plot = bokeh_renderer.get_plot(hm) xdim, ydim = hm.kdims source = plot.handles['source'] self.assertEqual(source.data['zvalues'], hm.dimension_values(2, flat=False).T.flatten()) self.assertEqual(source.data['x'], [xdim.pprint_value(v) for v in hm.dimension_values(0)]) self.assertEqual(source.data['y'], [ydim.pprint_value(v) for v in hm.dimension_values(1)])
def test_heatmap_invert_axes(self): arr = np.array([[0, 1, 2], [3, 4, 5]]) hm = HeatMap(Image(arr)).opts(invert_axes=True) plot = bokeh_renderer.get_plot(hm) xdim, ydim = hm.kdims source = plot.handles['source'] self.assertEqual(source.data['zvalues'], hm.dimension_values(2, flat=False).T.flatten()) self.assertEqual(source.data['x'], hm.dimension_values(1)) self.assertEqual(source.data['y'], hm.dimension_values(0))
def heatmap(self, x, y, data=None): data = data or self.data if not x: x = data.columns[0] if not y: y = data.columns[1] z = self.kwds.get('C', data.columns[2]) opts = dict(plot=self._plot_opts, norm=self._norm_opts, style=self._style_opts) hmap = HeatMap(data, [x, y], z).opts(**opts) if 'reduce_function' in self.kwds: return hmap.aggregate(function=self.kwds['reduce_function']) return hmap
def heatmap(self, x, y, data=None): data = self.data if data is None else data if not x: x = self.x or data.columns[0] if not y: y = self.y or data.columns[1] z = self.kwds.get('C', [c for c in data.columns if c not in (x, y)][0]) z = [z] + self.hover_cols opts = dict(plot=self._plot_opts, norm=self._norm_opts, style=self._style_opts) hmap = HeatMap(data, [x, y], z).redim(**self._redim).opts(**opts) if 'reduce_function' in self.kwds: return hmap.aggregate(function=self.kwds['reduce_function']) return hmap
def test_heatmap_invert_axes(self): arr = np.array([[0, 1, 2], [3, 4, 5]]) hm = HeatMap(Image(arr)).opts(plot=dict(invert_axes=True)) plot = mpl_renderer.get_plot(hm) artist = plot.handles['artist'] self.assertEqual(artist.get_array().data, arr.T[::-1, ::-1]) self.assertEqual(artist.get_extent(), (0, 2, 0, 3))
def test_heatmap_invert_yaxis(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]).options(invert_yaxis=True) plot = mpl_renderer.get_plot(hmap) array = plot.handles['artist'].get_array() expected = np.array([1, np.inf, np.inf, 2]) masked = np.ma.array(expected, mask=np.logical_not(np.isfinite(expected))) self.assertEqual(array, masked)
def test_heatmap_single_y_value(self): hmap = HeatMap((['A', 'B'], [1], np.array([[1, 2]]))) plot = bokeh_renderer.get_plot(hmap) cds = plot.handles['cds'] self.assertEqual(cds.data['y'], np.array([1, 1])) self.assertEqual(cds.data['x'], np.array(['A', 'B'])) self.assertEqual(cds.data['height'], [2.0, 2.0]) self.assertEqual(plot.handles['glyph'].width, 1)
def test_heatmap_categorical_axes_string_int(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]) plot = bokeh_renderer.get_plot(hmap) x_range = plot.handles['x_range'] y_range = plot.handles['y_range'] self.assertIsInstance(x_range, FactorRange) self.assertEqual(x_range.factors, ['A', 'B']) self.assertIsInstance(y_range, FactorRange) self.assertEqual(y_range.factors, ['1', '2'])
def test_heatmap_categorical_axes_string_int_inverted(self): hmap = HeatMap([('A',1, 1), ('B', 2, 2)]).opts(invert_axes=True) plot = bokeh_renderer.get_plot(hmap) x_range = plot.handles['x_range'] y_range = plot.handles['y_range'] self.assertIsInstance(x_range, Range1d) self.assertEqual(x_range.start, 0.5) self.assertEqual(x_range.end, 2.5) self.assertIsInstance(y_range, FactorRange) self.assertEqual(y_range.factors, ['A', 'B'])
def test_heatmap_categorical_axes_string_int_invert_xyaxis(self): opts = dict(invert_xaxis=True, invert_yaxis=True) hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]).opts(plot=opts) plot = bokeh_renderer.get_plot(hmap) x_range = plot.handles['x_range'] y_range = plot.handles['y_range'] self.assertIsInstance(x_range, FactorRange) self.assertEqual(x_range.factors, ['A', 'B'][::-1]) self.assertIsInstance(y_range, FactorRange) self.assertEqual(y_range.factors, ['1', '2'][::-1])
def test_heatmap_points_categorical_axes_string_int_inverted(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)])(plot=dict(invert_axes=True)) points = Points([('A', 2), ('B', 1), ('C', 3)]) plot = bokeh_renderer.get_plot(hmap * points) x_range = plot.handles['x_range'] y_range = plot.handles['y_range'] self.assertIsInstance(x_range, FactorRange) self.assertEqual(x_range.factors, ['1', '2', '3']) self.assertIsInstance(y_range, FactorRange) self.assertEqual(y_range.factors, ['A', 'B', 'C'])
def test_heatmap_points_categorical_axes_string_int(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]) points = Points([('A', 2), ('B', 1), ('C', 3)]) plot = bokeh_renderer.get_plot(hmap*points) x_range = plot.handles['x_range'] y_range = plot.handles['y_range'] self.assertIsInstance(x_range, FactorRange) self.assertEqual(x_range.factors, ['A', 'B', 'C']) self.assertIsInstance(y_range, Range1d) self.assertEqual(y_range.start, 0.5) self.assertEqual(y_range.end, 3)
def test_heatmap_alpha_dim(self): data = { "row": [1, 2, 1, 2], "col": [1, 2, 2, 1], "alpha": [0, 0, 0, 1], "val": [.5, .6, .2, .1] } hm = HeatMap(data, kdims=["col", "row"], vdims=["val", "alpha"]).opts(alpha="alpha") plot = bokeh_renderer.get_plot(hm) cds = plot.handles['cds'] self.assertEqual(cds.data['row'], np.array([1, 2, 1, 2])) self.assertEqual(cds.data['col'], np.array([1, 1, 2, 2])) self.assertEqual(cds.data['alpha'], np.array([0, 1, 0, 0])) self.assertEqual(cds.data['zvalues'], np.array([0.5, 0.1, 0.2, 0.6]))
def test_heatmap_extents(self): hmap = HeatMap([('A', 50, 1), ('B', 2, 2), ('C', 50, 1)]) plot = mpl_renderer.get_plot(hmap) self.assertEqual(plot.get_extents(hmap, {}), (-.5, -22, 2.5, 74))
def test_heatmap_xmarks_tuple(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]).options(xmarks=('A', 'B')) plot = mpl_renderer.get_plot(hmap) for marker, pos in zip(plot.handles['xmarks'], (0, 1)): self.assertEqual(marker.get_xdata(), [pos, pos])
def test_heatmap_colormapping(self): hm = HeatMap([(1, 1, 1), (2, 2, 0)]) self._test_colormapping(hm, 2)
def test_heatmap_ymarks_list(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]).options(ymarks=[0, 1]) plot = mpl_renderer.get_plot(hmap) for marker, pos in zip(plot.handles['ymarks'], (0, 1)): self.assertEqual(marker.get_ydata(), [pos, pos])
def test_heatmap_hover_ensure_vdims_sanitized(self): hm = HeatMap([(1, 1, 1), (2, 2, 0)], vdims=['z with $pace']) hm = hm(plot={'tools': ['hover']}) self._test_hover_info(hm, [('x', '@{x}'), ('y', '@{y}'), ('z with $pace', '@{z_with_pace}')])
def test_heatmap_ymarks_list(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]).options(ymarks=[0, 1]) plot = bokeh_renderer.get_plot(hmap) for marker, pos in zip(plot.handles['ymarks'], (2, 1)): self.assertEqual(marker.location, pos) self.assertEqual(marker.dimension, 'width')
def test_heatmap_xmarks_tuple(self): hmap = HeatMap([('A', 1, 1), ('B', 2, 2)]).options(xmarks=('A', 'B')) plot = bokeh_renderer.get_plot(hmap) for marker, pos in zip(plot.handles['xmarks'], (0, 1)): self.assertEqual(marker.location, pos) self.assertEqual(marker.dimension, 'height')
def test_heatmap_2d_index_columns(self): plot = self.df.hvplot.heatmap() self.assertEqual( plot, HeatMap((['x', 'y'], [0, 1, 2], self.df.values), ['columns', 'index'], 'value'))
def test_heatmap_dilate(self): hmap = HeatMap([('A',1, 1), ('B', 2, 2)]).options(dilate=True) plot = bokeh_renderer.get_plot(hmap) glyph = plot.handles['glyph'] self.assertTrue(glyph.dilate)