matplotlib / matplotlib/ipympl

Layout Templates and matplotlib figures

Offen
#207 16 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Jupyter Notebook
Sterne
1.7k
Forks
234
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

see #117 (issue) and #174 (PR) for some discussion on the topic.

@martinRenou I have been playing with using [Layout Templates](https://ipywidgets.readthedocs.io/en/latest/examples/Layout%20Templates.html) to stack figures in fun ways. Unfortunately, since matplotlib is currently responsible for the figure size, I end up with situations such as the following, where the figures are all cut off a bit. This is particularly noticable in `jupyter notebook` since the screen width is reduced.

In the following example, I stack a 4x4 of buttons and then a 4x4 of figures. The buttons stretch nicely, but the figures do not.

```python
%matplotlib widget
import matplotlib.pyplot as plt
from ipywidgets import TwoByTwoLayout
from ipywidgets.widgets import Button, Layout

# Buttons
def button(name):
return Button(description = name, layout=Layout(height='auto', width='auto'))

a,b,c,d = button("1"), button("2"), button("3"), button("4"),
layout_2x2 = TwoByTwoLayout(top_left=a,
top_right=b,
bottom_left=c,
bottom_right=d)
display(layout_2x2)

# Figures
figs = []
plt.ioff()
for i in range(4):
fig, ax = plt.subplots()
ax.imshow([[1,2], [3,4]])
figs.append(fig.canvas)

a,b,c,d = figs

layout_2x2 = TwoByTwoLayout(top_left=a,
top_right=b,
bottom_left=c,
bottom_right=d)
display(layout_2x2)
```

In `jupyter lab` the problem is less so, but still unfortunate that figures basically ignore the flexbox layout the widgets are designed with. I would set the size with matplotlib, but since I don't know the size of the viewport the user is using, it's likely that the size I choose will be too small or too large depending on the user.

I don't have a concrete solution at hand, but I'm wondering if we can come up with some logic that preserves aspect ratio but otherwise fills a widget to its fullest extent?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das Beispiel „Layout Templates“ aus dem Issue in Jupyter Notebook und JupyterLab nachzustellen, lies anschließend die Diskussion in #117 und die bestehende Arbeit in #174. Das gewünschte Ergebnis ist noch nicht definiert; kläre einen Ansatz, der es matplotlib-Figuren ermöglicht, das Widget-Layout auszufüllen und dabei ihr Seitenverhältnis beizubehalten, und lege anschließend fest, wie das Verhalten verifiziert werden sollte.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter-notebook, matplotlib
Bereich
frontend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.