如何使IPython笔记本matplotlib内联 [英] How to make IPython notebook matplotlib plot inline
问题描述
我正在尝试在MacOS X上使用Python 2.7.2和IPython 1.1.0上的IPython笔记本。
I am trying to use IPython notebook on MacOS X with Python 2.7.2 and IPython 1.1.0.
我无法让matplotlib图形显示为内联。
I cannot get matplotlib graphics to show up inline.
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
我还试过%pylab inline
和ipython命令行参数 - pylab = inline
但这没有区别。
I have also tried %pylab inline
and the ipython command line arguments --pylab=inline
but this makes no difference.
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>
和 matplotlib.get_backend()
显示我有'模块://IPython.kernel.zmq.pylab.backend_inline'
后端。
推荐答案
我在笔记本的第一个单元格中使用了%matplotlib inline
,它可以正常工作。我想你应该试试:
I used %matplotlib inline
in the first cell of the notebook and it works. I think you should try:
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
您也可以随时启动所有IPython内核默认情况下,通过在配置文件中设置以下配置选项来进行内联模式:
You can also always start all your IPython kernels in inline mode by default by setting the following config options in your config files:
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.
这篇关于如何使IPython笔记本matplotlib内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!