Skip to content

Figure layout height computation when **X axis label** is added behave weirdly in MaterialTemplate #8448

@xavArtley

Description

@xavArtley

ALL software version info

Python 3.12.5
Panel Version: 1.8.7

Figure layout height computation when X axis label is added behave weirdly in MaterialTemplate
Sometimes it's ok, sometimes no...

Image

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

pn.extension(design="material")


# Control widgets
button = pn.widgets.Button(name="Start streaming", button_type="success")

# Initial empty source to trigger the layout issue
source = ColumnDataSource(data={"x": [], "y": []})
p = figure(sizing_mode="stretch_both", title="Layout Issue MRE", x_axis_label="Frequency (kHz)", y_axis_label="Amplitude")
p.line(x="x", y="y", source=source, line_width=2)

x_val = 0
def update():
    global x_val
    new_x = np.arange(x_val, x_val + 10)
    new_y = np.random.randn(10)
    source.stream({"x": new_x, "y": new_y}, rollover=100)
    x_val += 10

cb = pn.state.add_periodic_callback(update, period=100, start=False)

def toggle_streaming(event=None):
    if cb.running:
        cb.stop()
        button.name = "Resume"
        button.button_type = "success"
    else:
        cb.start()
        button.name = "Stop"
        button.button_type = "danger"

button.on_click(toggle_streaming)

controls = pn.Column(
    "# Layout Bug MRE",
    "The figure starts empty. When streaming begins, the x axes often fail to display correctly within the MaterialTemplate.",
    button, width=300
)

template = pn.template.MaterialTemplate(title="Streaming Demo")
template.sidebar.extend(controls)
template.main.append(p)
template.servable()

Metadata

Metadata

Assignees

No one assigned

    Labels

    TRIAGEDefault label for untriaged issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions