无效的语法错误
问题描述:
我遇到了一些麻烦,进口低于降价,这是通过Twitter需要一个Python情感分析中显示以下库:无效的语法错误
# General:
import tweepy # To consume Twitter's API
import pandas as pd # To handle data
import numpy as np # For number computing
# For plotting and visualization:
from IPython.display import display
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib
虽然有些新的Python3 /作为一个Rubyist/elephpant,我肯定不是陌生人的自制软件 - 在注释掉%matplotlib
之后,该文件显然会导入除%matplotlib
之外的所有库,这似乎是the Jupyter invocation - 那么如何正确加载标准中的%matplotlib
导入Python(3.6.2)为了避免下面的错误?有其他方法吗?
File "toolbox.py", line 10
%matplotlib
^
SyntaxError: invalid syntax
谢谢!
答
与IPython的5.0启动和matplotlib 2.0,你可以尽量避免使用IPython中的特殊魔法和使用
matplotlib.pyplot.ion()
/matplotlib.pyplot.ioff()
具有工作IPython的外部以及的优势。
(重点煤矿)
所以你的情况,你可以只使用:
plt.ion()
代替裸%matplotlib
。
+0
完美!感谢您指引我朝着正确的方向发展 - 我还没有看到这些dox - 太专注于[matplotlib dox](http://matplotlib.org/)。再次感谢。 – alexanderjsingleton
'%matplotlib'是一个[IPython magic](http://ipython.readthedocs.io/en/stable/interactive/magics.html?highlight=magic#magic-matplotlib)。这是交互式使用。 – wim
Thanks @ wim - 你是否建议只评论'%matplotlib'或者那个和'将matplotlib.pyplot完全导入为plt'? – alexanderjsingleton