python SyntaxError:无效语法%matplotlib inline

Pra*_*bre 7 python matplotlib

我的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)
Run Code Online (Sandbox Code Playgroud)

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

San*_*Dey 9

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

如果你不使用Jupyter IPython笔记本,你笔记本中的第一个python代码单元应该有"%matplotlib inline"行,你可以查看任何一个情节.


小智 7

"%matplotlib inline" 不是有效的 python 代码,所以你不能把它放在脚本中。

我假设您使用的是 Jupyter 笔记本?如果是这样,把它放在第一个单元格中,一切都应该工作。