采用Pycharm用matplotlib绘图时报错AttributeError: module ‘matplotlib’ has no attribute ‘verbose’

51changxuePython评论790 views阅读模式

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()

 

运行结果如下:

 

 

采用Pycharm用matplotlib绘图时报错AttributeError: module ‘matplotlib’ has no attribute ‘verbose’

继续阅读
51changxue
  • 本文由 发表于 2018年3月10日 11:08:18
  • 转载请务必保留本文链接:https://51changxue.com/301.html
pycharm永久破解激活教程 Python

pycharm永久破解激活教程

PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、...
pycharm永久破解激活教程 Python

pycharm永久破解激活教程

PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、...
把文件隐藏在图片里 Python

把文件隐藏在图片里

素材:需要隐藏的文件,一张图片。 一、将需要隐藏的文件压缩成zip的压缩包。 二、新建一个txt文档输入如下命令: [code]copy /b image.jpg+file.zip=51changxu...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定