Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Figure resizing with AnyWidget doesn't work as expected #5208

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

Open
ndrezn opened this issue May 28, 2025 · 0 comments
Open

Figure resizing with AnyWidget doesn't work as expected #5208

ndrezn opened this issue May 28, 2025 · 0 comments

Comments

@ndrezn
Copy link
Member

ndrezn commented May 28, 2025

See: https://community.plotly.com/t/plotly-v6-0-figure-resizing-with-ipywidgets/89424

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)

5.24
Image

6.0
Image


A follow-up:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant