Better interactive Plotly figures for Jupyter notebooks.
- Resizable containers — drag the bottom-right corner to resize, Plotly auto-relayouts to fill.
- Legend-highlight — clicking a legend entry dims all other traces and darkens the selected traces instead of hiding anything. Click again to restore.
- No accidental hide-all — double-click on legend is suppressed.
| Before click | After click |
|---|---|
![]() |
![]() |
| Default view | After clicking first legend item (others dimmed, active darkened) |
pip install git+https://github.com/graphcore-research/plotlyjs-extras.gitimport plotly.graph_objects as go
from plotlyjs_extras import show_resizable
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1,2,3], y=[4,5,6], name="A", legendgroup="A"))
fig.add_trace(go.Scatter(x=[1,2,3], y=[6,5,4], name="B", legendgroup="B"))
show_resizable(fig, width="100%", height="500px", dim_opacity=0.1, active_darken=0.2)- Local notebook:
examples/legend_highlight_demo.ipynb - Colab:
| Parameter | Default | Description |
|---|---|---|
fig |
— | Plotly Figure to display |
width |
"100%" |
CSS width of the container |
height |
"500px" |
CSS height of the container |
dim_opacity |
0.1 |
Opacity for non-selected traces |
active_darken |
0.2 |
Blend selected trace colors toward black |
The figure is rendered as HTML via fig.to_html() inside a <div> with resize: both.
A small <script> block:
- Waits for Plotly to finish initializing (
gd._fullDatapolling). - Attaches a
ResizeObserverto keep the plot filling the container. - Overrides
plotly_legendclickto toggle opacity instead of visibility. - Suppresses
plotly_legenddoubleclick.
pip install -e .[dev]pytest -q
pytest -q tests/test_notebooks.pypython -m playwright install chromium
python scripts/generate_readme_screenshots.pyOutputs:
docs/assets/legend-before-click.pngdocs/assets/legend-after-click.png
MIT

