“%matplotlib inline"的目的是为了实现“ [英] Purpose of "%matplotlib inline"

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

问题描述

有人可以向我解释%matplotlib inline的确切用途吗?

Could someone explain to me what exactly is the use of %matplotlib inline?

推荐答案

%matplotlib

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

IPython具有一组预定义的魔术函数",您可以使用命令行样式的语法来调用它们.有两种魔术,面向行的和面向单元的.线魔术符以%字符作为前缀,其工作方式与OS命令行调用非常相似:它们作为行的其余部分作为参数,其中,参数传递时不带括号或引号.线魔术可以返回结果,并且可以在作业的右侧使用.单元格魔术的前缀为%%,并且它们是函数,它们不仅作为该行的其余部分作为参数,而且还作为单独的参数作为其底下的行的参数.

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笔记本之类的前端中,位于生成它的代码单元的正下方.生成的图也将存储在笔记本文档中.

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