How to use the holoviews.Image function in holoviews

To help you get started, we’ve selected a few holoviews examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github holoviz / holoviews / tests / operation / testdatashader.py View on Github external
def test_regrid_mean_xarray_transposed(self):
        img = Image((range(10), range(5), np.arange(10) * np.arange(5)[np.newaxis].T),
                    datatype=['xarray'])
        img.data = img.data.transpose()
        regridded = regrid(img, width=2, height=2, dynamic=False)
        expected = Image(([2., 7.], [0.75, 3.25], [[1, 5], [6, 22]]))
        self.assertEqual(regridded, expected)
github holoviz / holoviews / tests / operation / testoperation.py View on Github external
def test_operation_grid(self):
        grid = GridSpace({i: Image(np.random.rand(10, 10)) for i in range(10)}, kdims=['X'])
        op_grid = operation(grid, op=lambda x, k: x.clone(x.data*2))
        doubled = grid.clone({k: v.clone(v.data*2, group='Operation')
                              for k, v in grid.items()})
        self.assertEqual(op_grid, doubled)
github holoviz / holoviews / tests / operation / testdatashader.py View on Github external
def test_rasterize_quadmesh(self):
        qmesh = QuadMesh(([0, 1], [0, 1], np.array([[0, 1], [2, 3]])))
        img = rasterize(qmesh, width=3, height=3, dynamic=False, aggregator=ds.mean('z'))
        image = Image(np.array([[2., 3., np.NaN], [0, 1, np.NaN], [np.NaN, np.NaN, np.NaN]]),
                      bounds=(-.5, -.5, 1.5, 1.5))
        self.assertEqual(img, image)
github holoviz / holoviews / tests / core / data / testimageinterface.py View on Github external
def test_slice_datetime_xaxis(self):
        start = np.datetime64(dt.datetime.today())
        end = start+np.timedelta64(1, 's')
        bounds = (start, 0, end, 10)
        xs = date_range(start, end, 10)
        image = Image((xs, self.ys, self.array), bounds=bounds)
        sliced = image[start+np.timedelta64(530, 'ms'): start+np.timedelta64(770, 'ms')]
        self.assertEqual(sliced.dimension_values(2, flat=False),
                         self.array[:, 5:8])
github holoviz / holoviews / tests / element / testelementconstructors.py View on Github external
def test_image_casting(self):
        img = Image([], bounds=2)
        self.assertEqual(img, Image(img))
github holoviz / holoviews / tests / core / data / testdataset.py View on Github external
def test_canonical_vdim(self):
        x = np.array([ 0.  ,  0.75,  1.5 ])
        y = np.array([ 1.5 ,  0.75,  0.  ])
        z = np.array([[ 0.06925999,  0.05800389,  0.05620127],
                      [ 0.06240918,  0.05800931,  0.04969735],
                      [ 0.05376789,  0.04669417,  0.03880118]])
        dataset = Image((x, y, z), kdims=['x', 'y'], vdims=['z'])
        canonical = np.array([[ 0.05376789,  0.04669417,  0.03880118],
                              [ 0.06240918,  0.05800931,  0.04969735],
                              [ 0.06925999,  0.05800389,  0.05620127]])
        self.assertEqual(dataset.dimension_values('z', flat=False),
                         canonical)
github holoviz / holoviews / tests / testrenderclass.py View on Github external
def setUp(self):
        if pyplot is None:
            raise SkipTest("Matplotlib required to test widgets")

        self.basename = 'no-file'
        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.unicode_table = ItemTable([('β','Δ1'), ('°C', '3×4')],
                                       label='Poincaré', group='α Festkörperphysik')

        self.renderer = Store.renderer.instance()
github holoviz / holoviews / tests / core / data / testimageinterface.py View on Github external
def test_reduce_x_dimension(self):
        ys = np.linspace(0.5, 9.5, 10)
        zs = [0., 4.5, 9., 13.5, 18., 22.5, 27., 31.5, 36., 40.5]
        with DatatypeContext([self.datatype, 'dictionary' , 'dataframe'], Image):
            self.assertEqual(self.image.reduce(x=np.mean),
                             Curve((ys, zs), kdims=['y'], vdims=['z']))
github pyviz-topics / EarthSim / earthsim / grabcut.py View on Github external
    @param.output(image=hv.Image)
    def output(self):
        return self.get_tiff()
github AlexsLemonade / refinebio / workers / data_refinery_workers / processors / visualize.py View on Github external
try:
        dask_df = daskdf.from_pandas(input_frame, npartitions=multiprocessing.cpu_count()).persist()
        logger.info("Converted to Dask Frame..")

        num_genes, num_samples = input_frame.shape
        da = dask_df.to_dask_array(True).persist()
        logger.info("Converted to Dask Array..")

        viridis_bad_black = copy.copy(mpl.cm.get_cmap("viridis"))
        viridis_bad_black.set_bad(
            (1, 0, 1)
        )  # It's actually pink, but it shows up as white in bokeh

        # Visualize
        if backend == "matplotlib":
            img = hv.Image((np.arange(num_samples), np.arange(num_genes), da))
            rasterized_img = rasterize(img)
            rasterized_img.opts(cmap=viridis_bad_black, dpi=400, logz=True)
            hv.save(rasterized_img, output_path, backend=backend)
        else:
            img = hv.Image((np.arange(num_samples), np.arange(num_genes), da))
            rasterized_img = rasterize(img, width=width, height=height)
            rasterized_img.opts(width=width, height=height, cmap=viridis_bad_black, logz=True)
            hv.save(rasterized_img, output_path, backend="bokeh")

        logger.info("Output visualization!", output_path=output_path)
        return output_path

    except Exception as e:
        logger.exception(
            "Unable to visualize dataframe!",
            output_path=output_path,