Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bokeh plot uses more space than is available #4922

Open
huaracheguarache opened this issue May 23, 2023 · 4 comments
Open

Bokeh plot uses more space than is available #4922

huaracheguarache opened this issue May 23, 2023 · 4 comments
Labels
bokeh Request is for change in bokeh type: bug Something isn't correct or isn't working
Milestone

Comments

@huaracheguarache
Copy link

ALL software version info

Bokeh 3.1.1
Panel 1.0.2

Description of expected behavior and the observed behavior

Expected behaviour: Bokeh plot uses available space.

Observed behaviour: Bokeh plot uses more space than is available causing the plot tools to partially disappear behind the red spacer on the right. Tools reappear when plot dynamically updates when panning to non-negative y-values.

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

import numpy as np
from bokeh.plotting import figure
import panel as pn

plot = figure()
plot.sizing_mode = "stretch_both"

x = np.arange(-3, 3, 1)
y = x

plot.line(x, y)

grid = pn.GridSpec(sizing_mode="stretch_both")
grid[0, 0:4] = pn.pane.Bokeh(plot)
grid[0, 4] = pn.Spacer(styles={'background': '#cc241d'})

grid.servable()

Screenshots or screencasts of the bug in action

Screencast.from.2023-05-23.21-15-26.webm
@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label May 23, 2023
@philippjfr philippjfr added this to the v1.0.3 milestone May 23, 2023
@philippjfr
Copy link
Member

Thanks @huaracheguarache. We could definitely apply a fix here but this is probably better addressed in Bokeh itself. @mattpap if you inspect the DOM elements you can see that the <canvas> element overflows the bk-Canvas container:

Screen Shot 2023-05-24 at 10 25 53 Screen Shot 2023-05-24 at 10 25 41

@philippjfr philippjfr added the bokeh Request is for change in bokeh label May 24, 2023
@philippjfr
Copy link
Member

For now I'd just suggest adding some margin to the Bokeh plot.

@huaracheguarache
Copy link
Author

I've also discussed this issue on the Panel discourse forum, and I was able to produce an example where the Bokeh plot doesn't fully expand into the space it has available. I added a button that generated random data to plot with a scatterplot, and after generating new data a couple of times the plot dynamically updates and expands to occupy the entire available space. I believe this happens because the y-axis ticks lose a decimal in one of the updates causing the size of the figure to change.

Screencast.from.2023-05-23.15-56-05.webm
from numpy.random import default_rng
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
import panel as pn

rng = default_rng()

def calculate_coordinates():
   x_coordinates = rng.standard_normal(10)
   y_coordinates = rng.standard_normal(10)

   return {"x": x_coordinates, "y": y_coordinates}

data = calculate_coordinates()
source = ColumnDataSource(data)

def refresh_data(event):
   new_data = calculate_coordinates()
   new_source = ColumnDataSource(new_data)
   source.data.update(new_source.data)

plot = figure()
plot.sizing_mode = "stretch_both"

plot.circle(x="x", y="y", source=source)

button = pn.widgets.Button(name="Replot", button_type="primary", sizing_mode="stretch_both")
button.on_click(refresh_data)

grid = pn.GridSpec(sizing_mode="stretch_both")
grid[0, 0:3] = pn.pane.Bokeh(plot)
grid[0, 3] = button

grid.servable()

The following workaround was suggested, and it works:

grid = pn.GridSpec(sizing_mode="stretch_both")
def on_load():
    grid[0, 0:3] = pn.pane.Bokeh(plot)
    grid[0, 3] = button
pn.state.onload(on_load)

@mattpap
Copy link
Collaborator

mattpap commented May 24, 2023

This is another issue with resize observer. The layout is initially computed and then incorrectly readjusted. This can be "fixed" by recomputing the layout (Bokeh.index[grid_id].compute_layout() or by resizing the window, etc.).

@philippjfr philippjfr modified the milestones: v1.0.3, v1.0.4, v1.0.5 May 25, 2023
@philippjfr philippjfr modified the milestones: v1.0.5, v1.1.0, v1.2.0 Jun 5, 2023
@philippjfr philippjfr modified the milestones: v1.2.0, v1.2.1 Jul 10, 2023
@philippjfr philippjfr modified the milestones: v1.2.1, v1.2.2 Jul 25, 2023
@hoxbro hoxbro modified the milestones: v1.2.2, v1.2.3 Sep 4, 2023
@philippjfr philippjfr modified the milestones: v1.2.3, v1.2.4 Sep 18, 2023
@philippjfr philippjfr modified the milestones: v1.2.4, v1.3.0 Oct 9, 2023
@philippjfr philippjfr modified the milestones: v1.3.0, v1.3.1 Oct 23, 2023
@philippjfr philippjfr modified the milestones: v1.3.1, v1.3.2 Oct 31, 2023
@philippjfr philippjfr removed this from the v1.3.2 milestone Nov 22, 2023
@philippjfr philippjfr added this to the v1.4.0 milestone Nov 22, 2023
@philippjfr philippjfr modified the milestones: v1.4.0, v1.4.x Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bokeh Request is for change in bokeh type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

4 participants