如何使IPython Notebook Matplotlib内联绘图

本文提供了解决在IPython Notebook中无法显示Matplotlib内联图形的解决方案。用户分享了启动IPython Notebook时使用特定参数或者魔法命令的技巧,以及安装Anaconda Python来实现内联绘图的方法。
摘要由CSDN通过智能技术生成

本文翻译自:How to make IPython notebook matplotlib plot inline

I am trying to use IPython notebook on MacOS X with Python 2.7.2 and IPython 1.1.0. 我正在MacOS X上使用Python 2.7.2和IPython 1.1.0的情况下使用IPython Notebook。

I cannot get matplotlib graphics to show up inline. 我无法获得matplotlib图形来内联显示。

import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline  

I have also tried %pylab inline and the ipython command line arguments --pylab=inline but this makes no difference. 我也尝试了%pylab inline和ipython命令行参数--pylab=inline但这没什么区别。

x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('A simple chirp')
plt.show()

Instead of inline graphics, I get this: 我得到的不是内联图形,而是:

<matplotlib.figure.Figure at 0x110b9c450>

And matplotlib.get_backend() shows that I have the 'module://IPython.kernel.zmq.pylab.backend_inline' backend. matplotlib.get_backend()表明我有'module://IPython.kernel.zmq.pylab.backend_inline'后端。


#1楼

参考:https://stackoom.com/question/1JRRC/如何使IPython-Notebook-Matplotlib内联绘图


#2楼

I found a workaround that is quite satisfactory. 我找到了一种非常令人满意的解决方法。 I installed Anaconda Python and this now works out of the box for me. 我安装了Anaconda Python ,现在对我来说开箱即用。


#3楼

I'm not sure why joaquin posted his answer as a comment, but it is the correct answer: 我不确定为什么华金发表了他的回答作为评论,但这是正确的答案:

start ipython with ipython notebook --pylab inline ipython notebook --pylab inline启动ipython

Edit: Ok, this is now deprecated as per comment below. 编辑:好的,现在根据以下评论不推荐使用。 Use the %pylab inline magic command. 使用%pylab inline魔术命令。


#4楼

I used %matplotlib inline in the first cell of the notebook and it works. 我在笔记本的第一个单元格中使用了%matplotlib inline ,并且可以正常工作。 I think you should try: 我认为您应该尝试:

%matplotlib inline

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

You can also always start all your IPython kernels in inline mode by default by setting the following config options in your config files: 默认情况下,通过在配置文件中设置以下配置选项,您也可以始终始终以内联模式启动所有IPython内核:

c.IPKernelApp.matplotlib=<CaselessStrEnum>
  Default: None
  Choices: ['auto', 'gtk', 'gtk3', 'inline', 'nbagg', 'notebook', 'osx', 'qt', 'qt4', 'qt5', 'tk', 'wx']
  Configure matplotlib for interactive use with the default matplotlib backend.

#5楼

I have to agree with foobarbecue (I don't have enough recs to be able to simply insert a comment under his post): 我必须同意foobarbecue(我的建议不足,无法简单地在他的帖子下插入评论):

It's now recommended that python notebook isn't started wit the argument --pylab , and according to Fernando Perez (creator of ipythonnb) %matplotlib inline should be the initial notebook command. 现在建议不要使用--pylab参数启动python笔记本,根据Fernando Perez(ipythonnb的创建者)的说法, %matplotlib inline应该是笔记本的初始命令。

See here: http://nbviewer.ipython.org/github/ipython/ipython/blob/1.x/examples/notebooks/Part%203%20-%20Plotting%20with%20Matplotlib.ipynb 请参阅此处: http : //nbviewer.ipython.org/github/ipython/ipython/blob/1.x/examples/notebooks/Part%203%20-%20Plotting%20with%20Matplotlib.ipynb


#6楼

I did the anaconda install but matplotlib is not plotting 我做了anaconda安装,但是matplotlib没有绘制

It starts plotting when i did this 当我这样做时它开始绘图

import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值