Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

python - 如何使IPython Notebook Matplotlib内联绘图(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'后端。)

  ask by Ian Fiske translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...