如何检查matplotlib的pylab后端是否内联运行? [英] How to check that pylab backend of matplotlib runs inline?

查看:105
本文介绍了如何检查matplotlib的pylab后端是否内联运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改一个使用matplotlib绘制一些特殊图形的python模块。



现在,这个模块只是将所有数字保存为文件。



我希望能够在ipython笔记本中工作时导入模块并查看结果内联,另一方面我希望保留默认功能,将数字保存为在所有其他情况下导入模块时的文件。



所以我需要以某种方式检查模块是否在ipython笔记本中导入并且pylab是否内联操作。 / p>

如何查看?

解决方案

您可以查看matplotlib后端:

  import matplotlib 
matplotlib.get_backend()

特别要检查内联matplotlib:

  mpl_is_inline ='inline'在matplotlib.get_backend()

注意使用IPy通过笔记本电脑,您可以始终显示内联数字,无论活动的matplotlib后端如何,只需:

 显示(图)


I am modifying a python module that plots some special graphs using matplotlib.

Right now, this module just saves all figures as files.

I would like to make it possible to import the module while working in ipython notebook and see the results "inline", on the other hand I would like to keep the default functionality of saving the figures as files when the module is imported in all other cases.

So I need somehow to check if the module is imported in ipython notebook and the pylab is operating inline or not.

How can I check this?

解决方案

You can check the matplotlib backend with:

import matplotlib
matplotlib.get_backend()

To check for inline matplotlib in particular:

mpl_is_inline = 'inline' in matplotlib.get_backend()

Note that with the IPython notebook, you can always display inline figures, regardless of the active matplotlib backend, with:

display(fig)

这篇关于如何检查matplotlib的pylab后端是否内联运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆