matplotlib / matplotlib/ipympl

Nesting into HBox collapses plot width

Open
#125 1 comment 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.