Plotly v6.0 figure resizing with ipywidgets

Hi there,

With new release of plotly 6.0 I am not able to make a Figure fill its container anymore. Maybe this has to do with the switch to Anywidget. I am using jupyterlab v4.3 and plotly 6.0.0rc0.

Can anyone help?

Example

import ipywidgets as widgets
import plotly.graph_objs as go
from ipywidgets import HTML, VBox

fig = go.FigureWidget(data=[go.Scatter(x=[1, 2, 3], y=[4, 5, 6])])

custom_css = """
<style>
.plot-container {
    width: 100%;
    height: 100%;
}
</style>
"""
fig.add_class("plot-container")

container = VBox(
    [fig],
    layout=widgets.Layout(
        width="500px",
        height="600px",
        border="solid red",
    ),
)

display(HTML(custom_css), container)

Plotly 5.24

Plotly 6.0.0rc0

fig.layout.autosize = True

works, but it is poorly implemented. For example if it is set before displaying fig, it many times does not respect this decision. So I usually set it after display. Still if container size changes, it is not going well on its own and you may need to reset it. Honestly, to me it looks like sending a message through this trait which upon setting it again to same value works, although a Bool trait does not work like that. Ideally we should set this once and javascript behind the scene should observe the container size change automatically.

I opened this as an issue in Plotly.py: Figure resizing with AnyWidget doesn't work as expected ยท Issue #5208 ยท plotly/plotly.py ยท GitHub

Feel free to comment there, the team will take a look :raising_hands: