Missing datashade on overlay, till redraw?

Had problems displaying datashaded ‘flat’ scatter plots, after overlaying with other data, in one go.

In the below minimum example, if the next cell displays dscurve all cells show the correct data.

But by itself, dscurve * line , dscurve is ignored in the figure, till the user interacts with the figure controls, or forces another ‘visual’ notebook interaction on dscurve, i.e: displaying it alone in another cell.

Maybe the overlay operation is changing the “interpolation” range of ‘dscurve’ datashading operation? or its getting optimised out somehow? But then why would it appear when the user interacts with the figure…

Puzzled… If you think this is a bug, let me know where to raise the issue, holoviews? datashader?

Any work arounds to programatically force redrawing the “dscurve” without another cell, is also much appreciated…

Kind regards,
Oz

Minimum example below:

import holoviews as hv
import pandas as pd
import holoviews as hv
import param
import panel as pn
import numpy as np
import clads
hv.extension('bokeh')
renderer = hv.renderer('bokeh')
pn.extension()
import datashader as ds


from holoviews.operation.datashader import datashade, shade, dynspread, spread, rasterize
dynspread.max_px=20
dynspread.threshold=0.5

df = pd.DataFrame(np.array([3]*100).T, columns=['value'])

curve = hv.Scatter(df, 'index', vdims=['value'])
dscurve = dynspread(datashade(curve), shape='square', threshold=1e-20)

line = hv.VLine(df.index[50]).opts(color="red", line_width=0.2)

dscurve * line  

Hi @okz

So I have no idea of the why and what I’m doing really but I seem to have some odd behaviour as you you mention, for myself it’s almost as if the dynspread requires to be initialised.

So I rejigged things slightly and done the following which seemed to work in the end but not straight away…

import holoviews as hv
import pandas as pd
import holoviews as hv
import param
import panel as pn
import numpy as np
#import clads
hv.extension('bokeh')
renderer = hv.renderer('bokeh')
pn.extension()
import datashader as ds


from holoviews.operation.datashader import datashade, shade, dynspread, spread, rasterize
dynspread.max_px=20
dynspread.threshold=0.5

df = pd.DataFrame(np.array([3]*100).T, columns=['value'])
curve = hv.Scatter(df, 'index', vdims=['value'])
#dscurve = dynspread(datashade(curve), threshold=0.1)
dscurve = datashade(curve, cmap="green")
line = hv.VLine(df.index[50]).opts(color="red", line_width=0.2)
line*dynspread(dscurve, threshold=0.5, shape='square')

If I run the above straight away I get the following error - it’s shortened somewhat…


error part 2

For the above to work from a fresh kernel restart in jupyter lab I had to do the following run the code without any plotting and then plot the line curve, dscurve and finally dscurve individually - I didn’t try to see if there was an order going on.

import holoviews as hv
import pandas as pd
import holoviews as hv
import param
import panel as pn
import numpy as np
#import clads
hv.extension('bokeh')
renderer = hv.renderer('bokeh')
pn.extension()
import datashader as ds


from holoviews.operation.datashader import datashade, shade, dynspread, spread, rasterize
dynspread.max_px=20
dynspread.threshold=0.5

df = pd.DataFrame(np.array([3]*100).T, columns=['value'])
curve = hv.Scatter(df, 'index', vdims=['value'])
#dscurve = dynspread(datashade(curve), threshold=0.1)
dscurve = datashade(curve, cmap="green")
line = hv.VLine(df.index[50]).opts(color="red", line_width=0.2)

Now if I run the plotting in new cells in turn

line
bokeh_plot
curve
bokeh_plot (1)
dscurve
bokeh_plot (2)
line*curve
bokeh_plot (3)
line*dynspread(dscurve)
bokeh_plot (4)

It all seems to work in the end but I have zero idea what is happening and why, for me feels like either some initialisation needs to be done before dynspread or buggy, hopefully of some help

Thanks, Carl.

Thanks for looking trying this @carl

Had the same NaN to Integer issue as you on my original code, had done some debugging, and it looked like dscurve datashade is calculated lazily and is empty [ ], till it’s rendered alone, on screen.

Upgrading to the latest datashader: 0.12 and holoviews: 1.14.1 made the exception go away, but I believe the datashade was still empty till rendered alone, hence not displayed on the overlay.

A workaround would be forcing the datashade operation without displaying but couldn’t find a way.

Have raised an issue on github: https://github.com/holoviz/datashader/issues/988

Thanks…