Holoviews: `hv.Layout` with `sizing_mode=scale_both` on its elements results in empty plot

Created on 2 Feb 2019  路  6Comments  路  Source: holoviz/holoviews

Let's say you want to create a responsive hv.Layout with tabs. If the elements of a hv.Layout have sizing_mode=scale_both (or any sizing_mode other than fixed for that matter), the resulting plot will be empty.

I suspect this is related to @philippjfr's comment (https://github.com/ioam/holoviews/issues/1230#issuecomment-289912599):

The thing is that a Layout does not determine it's own size, instead all the elements making up a Layout do.

Below is a minimal example that reproduces the problem:

import numpy as np
import holoviews as hv

scatter_plots = [
    hv.Scatter(
        (np.random.randn(10), np.random.randn(10)),
        label=str(i)).opts(
            plot={
                'width': 300,
                'height': 300,
                'sizing_mode': 'scale_both'  # [1]
            })
    for i in range(5)]

hv.Layout(scatter_plots).opts(
    plot={
        'tabs': True,
        'sizing_mode': 'scale_both'
    })

# Displays an empty plot unless [1] is set to 'fixed'.

Most helpful comment

In 1.12 we will be completely overhauling the layouts, at that point you can set responsive=True which will default to scale both behavior.

All 6 comments

In 1.12 we will be completely overhauling the layouts, at that point you can set responsive=True which will default to scale both behavior.

Nice! Any estimate of when 1.12 would be ready for testing?

It's mostly waiting on bokeh 1.1.0 to be released, if you're happy to install a bokeh dev release you can play around with it on this branch https://github.com/pyviz/holoviews/pull/3450 right away.

Now that Holoviews 1.12.1 is out, I tried it again with your suggestion and with some slight modifications it does seem possible to get responsive graphs, nice!

However, the behaviour of responsive=True does not seem to be aligned with sizing_mode='scale_both', which is defined as [1]:

Component will responsively resize to both the available width and height, while maintaining the original or provided aspect ratio.

If you try to set both a width and a height with responsive=True, you get several warnings that look like:

WARNING:param.PointPlot08998: responsive mode could not be enabled because fixed width and height were specified.

Does that mean there is currently no way to specify the aspect ratio of a responsive graph?

import numpy as np
import holoviews as hv

hv.extension('bokeh')

scatter_plots = [
    hv.Scatter(
        (np.random.randn(10), np.random.randn(10)),
        label=str(i)).opts(
            height=300,  # Setting a `width` as well fails
            responsive=True)
    for i in range(5)]

hv.Layout(scatter_plots).opts(plot={'tabs': True})

[1] https://bokeh.pydata.org/en/latest/docs/reference/models/layouts.html#bokeh.models.layouts.LayoutDOM.sizing_mode

You should be able to specify the aspect or the data_aspect, depending on whether you want to specify the shape on the screen or the ratio of data values.

Great, thanks @jbednar! With that, I think this issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ceh-creare picture ceh-creare  路  5Comments

obust picture obust  路  5Comments

ahuang11 picture ahuang11  路  3Comments

nbren12 picture nbren12  路  5Comments

asmith26 picture asmith26  路  4Comments