matplotlib / matplotlib/ipympl

Layout Templates and matplotlib figures

未关闭
#207 16 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Jupyter Notebook
星标
1.7k
派生
234
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先在 Jupyter Notebook 和 JupyterLab 中复现 issue 里的 Layout Templates 示例,然后阅读 #117 中的讨论以及 #174 中已有的工作。期望的结果尚未定义;请明确一种方法,使 matplotlib 图形能够填充 widget layout,同时保持其宽高比,然后确定应如何验证该行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
jupyter-notebook, matplotlib
领域
frontend
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。