From 083b8473136ff7ea9d47dea2162dc42f83e66846 Mon Sep 17 00:00:00 2001 From: SharadhNaidu Date: Fri, 15 May 2026 12:14:33 +0530 Subject: [PATCH] Fix to_html responsive height by styling outer wrapper div The HTML produced by `to_html` wraps the figure in an outer `
` with no inline style. The inner figure div sets `height:100%`, but because the wrapper has no height, that 100% resolves to zero and plotly.js falls back to its hardcoded 450px. The result is that the documented default of `default_height='100%'` cannot inherit from a sized parent container, so figures embedded in responsive layouts (Jinja templates, Dash containers with `vh`/`%` heights, etc.) silently render at 450px. Move the requested dimensions onto the wrapper and let the inner figure div fill it. Pixel defaults still produce a fixed-size figure; percentage defaults now propagate from the parent container as the docstring claims. Closes #5591 --- CHANGELOG.md | 1 + plotly/io/_html.py | 4 ++-- tests/test_io/test_html.py | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccc184c23af..ced9e08f19b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Use presence of `COLAB_NOTEBOOK_ID` env var to enable Colab renderer instead of testing import of `google.colab` [[#5473](https://github.com/plotly/plotly.py/pull/5473)], with thanks to @kevineger for the contribution! - Update tests to be compatible with numpy 2.4 [[#5522](https://github.com/plotly/plotly.py/pull/5522)], with thanks to @thunze for the contribution! - Add default headers to be passed in to Kaleido v1.3.0 to avoid blocked Open Street Map tiles [#5588](https://github.com/plotly/plotly.py/pull/5588)] +- Propagate the requested `default_height`/`default_width` to the outer wrapper div produced by `to_html` so that responsive (percentage) dimensions inherit from a sized parent container instead of collapsing to the plotly.js 450px fallback [[#5591](https://github.com/plotly/plotly.py/issues/5591)] ### Updated - The `__eq__` method for `graph_objects` classes now returns `NotImplemented` to give the other operand an opportunity to handle the comparison [[#5547](https://github.com/plotly/plotly.py/pull/5547)], with thanks to @RazerM for the contribution! diff --git a/plotly/io/_html.py b/plotly/io/_html.py index a9ff68c23ea..c2153dc5b0b 100644 --- a/plotly/io/_html.py +++ b/plotly/io/_html.py @@ -318,11 +318,11 @@ def to_html( ) plotly_html_div = """\ -
\ +
\ {mathjax_script}\ {load_plotlyjs}\
\ +style="height:100%; width:100%;">
\