plot() doesn't work on IPython notebook

此生再无相见时 提交于 2019-12-03 01:17:57

It is not advisable to use pylab mode. See the following post from Matthias Bussonnier

A summary from that post:

Why not to use pylab flag:

  1. It is irreversible- Cannot unimport
  2. Unclear- if someone else did not run with this flag (or with a different setting of it) what would happen?
  3. Pollutes the namespace
  4. Replaces built-ins
  5. Side effects

You are much better by doing the following inside your IPython notebook.

%matplotlib inline

import matplotlib.pyplot as plt
plt.plot(range(10))

The following is the code which --pylab brings into the namespace

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot

from IPython.core.pylabtools import figsize, getfigs

from pylab import *
from numpy import *

Still, if you wish to use pylab and have plots inline, you may do either of the following:

From shell:

$ ipython notebook --pylab inline

Or, from within your notebook

%pylab inline
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!