python 语法错误: invalid syntax %matplotlib inline

标签 python matplotlib plot jupyter-notebook jupyter

我在我的 python 脚本中遇到了这个错误:

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

from utils import progress_bar_downloader
import os
#Hosting files on my dropbox since downloading from google code is painful
#Original project hosting is here: https://code.google.com/p/hmm-speech-recognition/downloads/list
#Audio is included in the zip file
link = 'https://dl.dropboxusercontent.com/u/15378192/audio.tar.gz'
dlname = 'audio.tar.gz'

if not os.path.exists('./%s' % dlname):
    progress_bar_downloader(link, dlname)
    os.system('tar xzf %s' % dlname)
else:
    print('%s already downloaded!' % dlname)

我想使用 matplotlib 但它给出了语法错误, 我试过 sudo apt-get install python-matplotlib

最佳答案

如果您不使用 Jupyter IPython notebook,只需注释掉(或删除)该行,一切都会正常工作,如果您从控制台运行 python 脚本,则会打开一个单独的绘图窗口。

但是,如果您使用的是 Jupyter IPython 笔记本,笔记本中的第一个 Python 代码单元应该有“%matplotlib inline”行,以便您能够查看任何绘图。

关于 python 语法错误: invalid syntax %matplotlib inline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39449549/

相关文章:

python - Redis MGET 性能

python - python中是否有一个函数可以填充两个轮廓线之间的区域,每个轮廓线由不同的函数给出?

python - 尽管设置了 alpha,3D 表面仍不透明

r - 经验 CDF 函数 `ecdf` 不适用于 "xts"时间序列

python - 使用阈值在层次聚类中自动化聚类

python - 将函数转换为 Lambda

python - 为什么此幂函数在负指数情况下返回零?

python - 实时更新连续函数

matlab - 一次绘制可变数量的向量?

R:plotmath 表达式符号未显示在交互图中