matplotlib / matplotlib/ipympl
Nesting into HBox collapses plot width
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 1.7k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
Here's another effect of requiring the canvas size explicitly, but somehow isn't visible unless the plot gets dropped into an ipywidgets layout (e.g. by a downstream package).
If the interactive matplotlib is the child of one p-Panel, it's fine. But gets squashed as the child of two p-Panels (regardless of orientation).
Explicitly setting canvas.layout.width fixes it, and propagates to the front-end as expected.
```
from ipywidgets import HTML, HBox, VBox
from matplotlib.figure import Figure
from ipympl.backend_nbagg import Canvas, FigureManager
figure = Figure()
canvas = Canvas(figure)
canvas.manager = FigureManager(canvas, 0)
axes = figure.add_subplot(1,1,1)
HBox([HBox([HTML(''), canvas])])
```
```
HBox([canvas])
```


Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Canvas/FigureManager reproducer in a notebook, comparing a canvas in one HBox with the same canvas nested in two HBoxes. Investigate how the canvas size is propagated to ipywidgets layouts; done means the plot keeps its width when nested without explicitly setting canvas.layout.width.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, matplotlib, python
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100