holoviews icon indicating copy to clipboard operation
holoviews copied to clipboard

data_aspect and responsive do not work together when data_aspect>1

Open basnijholt opened this issue 1 year ago • 4 comments

ALL software version info

  • HoloViews tried latest master and latest release
  • Bokeh 2.4.2

Description of expected behavior and the observed behavior

data_aspect and responsive do not work together when data_aspect>1.

The width of the plot seems to get set to 0.

Complete, minimal, self-contained example code that reproduces the issue

Here I am plotting the figure twice, once with just HoloViews and once by first rendering and then calling bokeh.io.show

import holoviews as hv
import bokeh.io

hv.notebook_extension("bokeh")


i = 1 + 1e-3  # Change to just 1, and the problem is gone!

p = hv.Polygons({"x": [0, 1, 1, 0], "y": [0, 0, i, i]}).opts(
    responsive=True, data_aspect=1, min_height=50
)
display(p)  # shows messed-up figure
bokeh.io.show(hv.render(p, "bokeh"))  # correctly shows figure

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

image

basnijholt avatar Jul 21 '22 17:07 basnijholt

TL:DR: This is properly a bokeh problem and has been fixed upstream.


So I can somewhat recreate this problem. I'm using bokeh 2.4.3 and the latest master of holoviews. The difference is either that they both fail or both succeed.

With i = 1.001 image

HoloViews uses a different (older?) version of defining a plot's dimension and aspect properties. These properties are then converted to Bokeh definition with this function:

https://github.com/holoviz/holoviews/blob/67f1fcf35586fdd2e9d83786e3110f87310123dd/holoviews/plotting/bokeh/util.py#L185-L188

So comparing Bokeh properties for i = 1 and i = 1.001,

image

image

Where the relevant properties are: min_height, sizing_mode, and aspect_ratio. This can then be converted to bokeh only example:

from bokeh.plotting import figure, output_file, show
import bokeh.io

# instantiating the figure object
graph = figure(min_height=50, sizing_mode="scale_both", aspect_ratio=0.999)
    
# the points to be plotted
xs = [[[[0, 1, 1, 0]]]]
ys = [[[[0, 0, 1, 1]]]]
     
# plotting the graph
graph.multi_polygons(xs, ys)

# displaying the model
bokeh.io.show(graph)

This will fail for some combinations and not for other combinations:

Failure Success
image image

Luckily, this has been fixed by Bokeh. Running the example which failed on the latest dev release, we get: Screenshot 2022-07-29 at 11-10-00 Bokeh Plot

hoxbro avatar Jul 29 '22 10:07 hoxbro

Thanks a lot for your detailed answer @Hoxbro! Are you aware of which Bokeh issue/PR solved this problem?

basnijholt avatar Jul 29 '22 16:07 basnijholt

No, the new version of Bokeh has an entirely new layout engine, which is properly what fixed it.

It could be a single PR that has fixed it, but I haven't looked.

hoxbro avatar Jul 29 '22 16:07 hoxbro

@Hoxbro, is it already possible to use the new bokeh with HoloViews?

I have tried but there seems to be an incompatibility with panel.

Edit: I just found https://github.com/holoviz/panel/pull/3752

basnijholt avatar Aug 31 '22 20:08 basnijholt

Running the current main of Panel and HoloViews with bokeh3.1.dev2, we get the following output

So soon you will be able to run this example without it collapsing :slightly_smiling_face:

image

hoxbro avatar Feb 09 '23 12:02 hoxbro

That's great! I am looking forward to Bokeh 3 support 😄

basnijholt avatar Feb 10 '23 21:02 basnijholt