Pycharm中matplotlib出错

Pycharm中matplotlib出错

用python里面的matplotlib画3D图,运行代码如下

import numpy
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

theta = numpy.linspace(0, 3.14*4, 200)
r = numpy.linspace(0, 1, 200)
x = r * numpy.cos(theta)
y = r * numpy.sin(theta)
z = numpy.linspace(0, 2, 200)

fig = plt.figure(figsize=(12, 7))
ax1 = plt.axes(projection='3d')
ax1.plot(x, y, z)
plt.show()

但是matplotlib一直出错,错误如下

Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/Introduction to Python3/Introduction to Python Smallpiece 2018/Variables/3Dpictures.py", line 2, in <module>
    import matplotlib.pyplot as plt
  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\matplotlib\pyplot.py", line 2372, in <module>
    switch_backend(rcParams["backend"])
  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\matplotlib\pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "D:\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\matplotlib\backends\backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\matplotlib\backends\_backend_tk.py", line 11, in <module>
    from . import _tkagg
ImportError: cannot import name '_tkagg' from 'matplotlib.backends' (C:\Users\user\AppData\Roaming\Python\Python37\site-packages\matplotlib\backends\__init__.py)

Process finished with exit code 1

求各位大佬帮忙解决一下

上一篇:mlbox ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interacti


下一篇:上架到AppStore?第一次上架之路