“%matplotlib inline"的目的 [英] Purpose of "%matplotlib inline"

查看:27
本文介绍了“%matplotlib inline"的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

%matplotlib inline到底有什么用?

推荐答案

%matplotlib 是一个 IPython 中的魔法函数.为方便起见,我将在此处引用相关文档供您阅读:

%matplotlib is a magic function in IPython. I'll quote the relevant documentation here for you to read for convenience:

IPython 有一组预定义的魔法函数",您可以使用命令行样式的语法调用它们.有两种魔法,面向线和面向细胞.行魔法以 % 字符为前缀,其工作方式与操作系统命令行调用非常相似:它们将行的其余部分作为参数获取,其中传递的参数不带括号或引号.Lines magics 可以返回结果,并且可以在赋值的右侧使用.单元格魔法以双 %% 为前缀,它们是不仅将行的其余部分作为参数,而且在单独的参数中将其下方的行作为参数的函数.

IPython has a set of predefined ‘magic functions’ that you can call with a command line style syntax. There are two kinds of magics, line-oriented and cell-oriented. Line magics are prefixed with the % character and work much like OS command-line calls: they get as an argument the rest of the line, where arguments are passed without parentheses or quotes. Lines magics can return results and can be used in the right hand side of an assignment. Cell magics are prefixed with a double %%, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument.

%matplotlib inline 将 matplotlib 的后端设置为内联"后端:

使用此后端,绘图命令的输出在 Jupyter notebook 等前端内嵌显示,直接位于生成它的代码单元下方.生成的图也将存储在笔记本文档中.

With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.

使用内联"后端时,您的 matplotlib 图形将包含在您的笔记本中,代码旁边.可能还值得一读 如何制作 IPython 笔记本 matplotlib 图内联 以供参考如何在您的代码中使用它.

When using the 'inline' backend, your matplotlib graphs will be included in your notebook, next to the code. It may be worth also reading How to make IPython notebook matplotlib plot inline for reference on how to use it in your code.

如果您还想要交互性,可以使用 nbagg 后端 使用 %matplotlib notebook(在 IPython 3.x 中),如 此处.

If you want interactivity as well, you can use the nbagg backend with %matplotlib notebook (in IPython 3.x), as described here.

这篇关于“%matplotlib inline"的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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