今天继续学习python的机器学习,使用了jupyter notebook,学习到绘图模块,结果遇到了bug,情况是
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["xtick.labelsize"] = 16
plt.rcParams["xtick.color"] = "red"
fig = plt.figure()
这种情况下运行没有出来图形,结果是
<matplotlib.figure.Figure at 0x110b9c450>
如果使用运行
fig.show()
则报错:
UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure "matplotlib is currently using a non-GUI backend, "
最后找了半天,尝试了很多解决方案,发现改动一点就可以了:在最前面添加上这行代码即可
%matplotlib notebook
结果如下: