mplot3d中没有名为externals的模块

时间:2017-11-15 13:36:34

标签: python matplotlib mplot3d

我正在尝试使用mpl_toolkits.mplot3d.Axes3D和matplotlib来显示3d图

我正在使用python 3和matplot版本'2.1.0'以及scikit-learn verison 0.19.0。当我运行代码时,它产生以下错误,

from matplotlib.externals import six
ImportError: No module named 'matplotlib.externals'

我尝试通过删除现有的matplotlib并重新安装来解决此问题,但没有任何运气。

我正在尝试运行此代码

import numpy as np
import mglearn
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from mpl_toolkits.mplot3d import Axes3D, axes3d


X, y = make_blobs(centers=4, random_state=8)
y = y % 2

X_new = np.hstack([X, X[:, 1:] ** 2])

figure = plt.figure()
ax = Axes3D(figure, elev=-152, azim=-26)
# plot first all the points with y == 0, then all with y == 1
mask = y == 0
ax.scatter(X_new[mask, 0], X_new[mask, 1], X_new[mask, 2], c='b', cmap=mglearn.cm2, s=60)
ax.scatter(X_new[mask, 0], X_new[mask, 1], X_new[mask, 2], c='r', marker='^', cmap=mglearn.cm2, s=60)
ax.set_xlabel("feature0")
ax.set_ylabel("feature1")
ax.set_zlabel("feature1 ** 2")

plt.show()

Error log after installing sabron package
The minimum supported version is 2.4.6

  ver=ver, min_ver=_MIN_NUMEXPR_VERSION), UserWarning)
Traceback (most recent call last):
  File "/home/asif/ml-codes/matpolitlib-tutorials/example-two.py", line 5, in <module>
    from mpl_toolkits.mplot3d import Axes3D, axes3d
  File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/__init__.py", line 4, in <module>
    from matplotlib.externals import six
ImportError: No module named 'matplotlib.externals'

1 个答案:

答案 0 :(得分:0)

执行:

sudo apt-get remove python3-matplotlib

这将根据您的错误日志删除/usr/lib/python3/dist-packages/中的版本。