1.采用pycharm,在用matplotlib绘图时,报错:
源代码:
import matplotlib.pyplot as plt squares = [1, 4, 9, 16, 25] plt.plot(squares) plt.show()
报错:
Traceback (most recent call last): File "E:/Python-example/test1/mpl_squares.py", line 2, in <module> import matplotlib.pyplot as plt File "D:\Program Files\Python\lib\site-packages\matplotlib\pyplot.py", line 115, in <module> _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "D:\Program Files\Python\lib\site-packages\matplotlib\backends\__init__.py", line 62, in pylab_setup [backend_name], 0) File "D:\Program Files\JetBrains\PyCharm 2017.3.3\helpers\pycharm_matplotlib_backend\backend_interagg.py", line 17, in <module> verbose = matplotlib.verbose AttributeError: module 'matplotlib' has no attribute 'verbose'
2.解决办法:
在源文件开头添加:
import matplotlib as mpl mpl.use('Qt5Agg')
最后代码如下:
import matplotlib as mpl mpl.use('Qt5Agg') import matplotlib.pyplot as plt squares = [1, 4, 9, 16, 25] plt.plot(squares) plt.show()
运行结果如下:
评论