# Lazy dask plotting

**URL:** <https://discourse.holoviz.org/t/lazy-dask-plotting/3068>\
**Category:** Datashader\
**Tags:** dask\
**Created:** [November 11, 2021, 12:36pm UTC](https://discourse.holoviz.org/t/lazy-dask-plotting/3068 "2021-11-11T12:36:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmfreeze](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/fmfreeze/32/1704_2.png) [@fmfreeze](https://discourse.holoviz.org/u/fmfreeze)\
**Post date:** [November 11, 2021, 12:36pm UTC](https://discourse.holoviz.org/t/lazy-dask-plotting/3068/1 "2021-11-11T12:36:28Z")

</div>

I love holoviz tools now for years.  
As I increasingly have to deal with “BigData” (larger than memory data), please demystify and dewind my head in one core thing around datashader and dask I thought both together are capable of:

Can datashader plot data from a huge (let’s say 500GB) lazy dask array without the need of coding logic around loading chunks and .compute() them?

Trying to datashade a 5GB lazy dask array, it takes much, much, much longer to plot than call .compute() and then datashading it.

The data is stored in (multiple) hdf5 files, dask chunks are aligned with hdf5 chunks.

---

<div class="post-metadata">

**Author:** ![philippjfr](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/philippjfr/32/7_2.png) [@philippjfr](https://discourse.holoviz.org/u/philippjfr)\
**Post date:** [November 11, 2021, 12:54pm UTC](https://discourse.holoviz.org/t/lazy-dask-plotting/3068/2 "2021-11-11T12:54:30Z")

</div>

Loading data from disk will always take a while there’s nothing datashader can do about that (although there’s probably some work we could do to optimize that, e.g. by computing the plot ranges efficiently). That said if you do have the memory available or a cluster to distribute to you can still leverage dask by using `.persist()` instead of `.compute()`. That will load the data into memory but still allow datashader to parallelize over each chunk.

---

<div class="post-metadata">

**Author:** ![fmfreeze](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/fmfreeze/32/1704_2.png) [@fmfreeze](https://discourse.holoviz.org/u/fmfreeze)\
**Post date:** [November 11, 2021, 1:11pm UTC](https://discourse.holoviz.org/t/lazy-dask-plotting/3068/3 "2021-11-11T13:11:43Z")

</div>

Does that also mean, either `.persist()` or `.compute()` should be used?  
Just passing the lazy dask array works, but seems to be very inefficient.

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [November 11, 2021, 4:51pm UTC](https://discourse.holoviz.org/t/lazy-dask-plotting/3068/4 "2021-11-11T16:51:41Z")

</div>

Some related posts

> [@Larger than memory plotting: how to set initial slice to plot](https://discourse.holoviz.org/t/larger-than-memory-plotting-how-to-set-initial-slice-to-plot/2570/8):
>
> Okay, I think this works import h5py import numpy as np import panel as pn import xarray as xr import holoviews as hv import dask.array as da from holoviews.operation.datashader import rasterize, shade hv.extension('bokeh', logo=False) f = h5py.File('data.h5', "r") full\_data = da.from\_array(f['data'], chunks=(60\*60, 2401), name=False) da = xr.DataArray( full\_data, dims=("x", "y"), coords={"x": np.arange(full\_data.shape[0]), "y": np.arange(full\_data.shape[1])}, ) class BigSpectrogr…

> [@How to plot a huge image out of memory?](https://discourse.holoviz.org/t/how-to-plot-a-huge-image-out-of-memory/2818):
>
> It loads the entire dataset before doing anything (and crashes), so I was wondering if it could just skip every 10 at farthest zoom (e.g. is there a decimate function for datashader outside of hv)? import numpy as np import dask.array as da import xarray as xr from datashader import transfer\_functions as tf def sample(range\_=(0.0,2.4)): xs = da.arange(700000, dtype=np.float32) ys = da.arange(280000, dtype=np.float32) return xr.DataArray( da.random.random((len(ys), len(xs)),…

Also, perhaps converting to zarr format can help

---

<div class="post-metadata">

**Author:** ![fmfreeze](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/fmfreeze/32/1704_2.png) [@fmfreeze](https://discourse.holoviz.org/u/fmfreeze)\
**Post date:** [November 23, 2021, 10:19am UTC](https://discourse.holoviz.org/t/lazy-dask-plotting/3068/5 "2021-11-23T10:19:02Z")

</div>

Thanks, I don’t use a distributed cluster, so I’m stuck on a local machine.  
Remains the question:  
Why is it uncomparably MUCH fast to use `datashade(da.compute())` instead of just using `datashade(da)` on the same amount of data, even when it easily fits into memory?

---

<div class="post-metadata">

**Author:** ![philippjfr](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/philippjfr/32/7_2.png) [@philippjfr](https://discourse.holoviz.org/u/philippjfr)\
**Post date:** [November 23, 2021, 5:14pm UTC](https://discourse.holoviz.org/t/lazy-dask-plotting/3068/6 "2021-11-23T17:14:12Z")

</div>

> [@fmfreeze](#):
>
> Why is it uncomparably MUCH fast to use `datashade(da.compute())` instead of just using `datashade(da)` on the same amount of data, even when it easily fits into memory?

Are you using `da.persist()`? Because otherwise you are still forcing it to load data into memory (multiple times) during the datashading step, which is not a fair comparison.
