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

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

问题描述

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

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

现在,这个模块只是将所有图形保存为文件.

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

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

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.

所以我需要以某种方式检查模块是否已导入 ipython notebook 并且 pylab 是否内联运行.

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

我该如何检查?

推荐答案

您可以通过以下方式检查 matplotlib 后端:

You can check the matplotlib backend with:

import matplotlib
matplotlib.get_backend()

要特别检查内联 matplotlib:

To check for inline matplotlib in particular:

mpl_is_inline = 'inline' in matplotlib.get_backend()

请注意,使用 IPython 笔记本,您可以始终显示内嵌图形,而不管活动的 matplotlib 后端如何,使用:

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天全站免登陆