API ipython 中的内联图形
API for inline graphics in ipython
我在 python 中创建了一个可以生成图形的小型库,我希望能够在 ipython 中显示其对象,就像在 %matplotlib inline
中一样。
是否有一些库可以让我以简单的方式完成这项工作?
如果显示可以交互,则加分。
来自关于如何添加丰富的对象显示的文档:
http://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display
只要您控制class定义,您就可以添加_repr_*_
方法,例如_repr_png_
或 _repr_html_
。请注意,它们被 单个 下划线包围,这与 Python 自己的魔法 __repr__
方法不同。 HTML 等文本数据应以字符串形式返回,PNG 等二进制数据应以字节形式返回。
如果您不控制class定义,您可以单独注册格式化程序:
get_ipython().display_formatter.formatters['image/png'].for_type(MyType, func)
我在 python 中创建了一个可以生成图形的小型库,我希望能够在 ipython 中显示其对象,就像在 %matplotlib inline
中一样。
是否有一些库可以让我以简单的方式完成这项工作? 如果显示可以交互,则加分。
来自关于如何添加丰富的对象显示的文档: http://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display
只要您控制class定义,您就可以添加_repr_*_
方法,例如_repr_png_
或 _repr_html_
。请注意,它们被 单个 下划线包围,这与 Python 自己的魔法 __repr__
方法不同。 HTML 等文本数据应以字符串形式返回,PNG 等二进制数据应以字节形式返回。
如果您不控制class定义,您可以单独注册格式化程序:
get_ipython().display_formatter.formatters['image/png'].for_type(MyType, func)