matplotlib / matplotlib/ipympl

Using ipympl logic inside python shell or ipython?

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

还没有人认领这个 Issue。

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

描述

I have a class that inherits from the `ipywidgets.widgets.VBox` and adds a `figure.canvas` instance of a matplotlib figure to its children like so:

```python
import matplotlib.pyplot as plt
from ipywidgets import widgets

plt.ioff()

class MyVis(widgets.VBox):
def __init__(self):
super().__init__()
self.fig = plt.figure()
self.children = [self.fig.canvas]

m = MyVis()
```

This works fine when I use this class within jupyter notebooks using the `%matplotlib widget` magic before executing the above code.
When executed within ipython I get
`TraitError: Element of the 'children' trait of a MyVis instance must be a Widget, but a value of was specified.`
since of course `ipympl` and its magic are not active.

Since I also want to have unit-tests for this class (and others that make use of this class) using `pytest`, it would be nice to get around this problem.
Can I enable the `ipympl` way of handling figures somehow in the python shell (similar to using the `%matplotlib widget` magic in the notebook) that would allow my tests to run?

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 MyVis 示例开始,在 IPython 中重现 TraitError,然后将其与使用 `%matplotlib widget` magic 的 notebook 设置进行比较。检查 matplotlib canvas 的选择方式,并确定什么样的测试设置可以让 pytest 测试用例在 Jupyter 之外使用兼容的 widget canvas;当该类能够在不出现 Tk canvas 错误的情况下被实例化和测试时,即表示完成。

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

评估

技术栈
jupyter, python
领域
backend, testing
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
28/100

把新 issue 发到你的邮箱

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