使用下面代码时报错
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
删除这行代码无法绘图并报错
Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
查阅资料:要添加以下代码
matplotlib.use('TkAgg')
添加后还是报同样错误,但出现画图框,之后程序出现卡死现象,只能重启
再次查阅资料,发现需要将%matplotlib inline
替换
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
最终代码如下所示:
import matplotlib
import matplotlib.pyplot as plt
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')