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 instead of hiding them. Click again to restore.
- No accidental hide-all — double-click on legend is suppressed.
pip install plotlyjs-extras # from PyPI (once published)
pip install -e /path/to/plotlyjs-extras # local dev installimport 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)| 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 |
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.
MIT