【问题标题】:Jupyter & IPython: What does %matplotlib inline do?Jupyter & IPython:%matplotlib inline 有什么作用?
【发布时间】:2016-10-28 22:40:18
【问题描述】:

我很好奇 jupyter notebook 如何启用内联情节。 我在github中搜索了%matplotlib inline,没有找到源代码(https://github.com/search?l=python&q=org%3Ajupyter+matplotlib+inline&ref=searchresults&type=Code&utf8=%E2%9C%93)。

而且它在文档 (http://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-matplotlib) 中不可用。

谁能告诉我在哪里可以看到%matplotlib inline的源代码?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您可以通过以下方式在 jupyter notebook 中找到 matplotlib 魔法的来源

    %matplotlib?? # view source
    

    由此我们找到python3.5/site-packages/IPython/core/magics/pylab.py中的代码

        args = magic_arguments.parse_argstring(self.matplotlib, line)
        if args.list:
            backends_list = list(backends.keys())
            print("Available matplotlib backends: %s" % backends_list)
        else:
            gui, backend = self.shell.enable_matplotlib(args.gui)
            self._show_matplotlib_backend(args.gui, backend)
    

    执行这项工作的行是 self.shell.enable_matplotlib。您可以在 IPython github 存储库中找到它:https://github.com/ipython/ipython/blob/aa586fd81940e557a1df54ecd0478f9d67dfb6b4/IPython/core/magics/pylab.py#L100

    这从interactiveshell.py调用代码:https://github.com/ipython/ipython/blob/aa586fd81940e557a1df54ecd0478f9d67dfb6b4/IPython/core/interactiveshell.py#L2918-L2961

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 2017-09-18
      • 2023-03-29
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多