matplotlib / matplotlib/ipympl

Layout Templates and matplotlib figures

Aperta
#207 16 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Jupyter Notebook
Stelle
1.7k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

@martinRenou I have been playing with using Layout Templates 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.

%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?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo l'esempio Layout Templates dell'issue in Jupyter Notebook e JupyterLab, quindi leggi la discussione in #117 e il lavoro esistente in #174. Il risultato desiderato non è ancora definito; chiarisci un approccio che consenta alle figure matplotlib di riempire il layout del widget preservandone le proporzioni, quindi stabilisci come dovrebbe essere verificato il comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
jupyter-notebook, matplotlib
Ambito
frontend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.