0

I am trying to visualize the 3d plot using mpl_toolkits.mplot3d.Axes3D with matplotlib

I am using python 3 with matplot version '2.1.0' and scikit-learn verison 0.19.0. When i run the code it is producing the following error,

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

I tried to solve this issue by removing existing matplotlib and installing again, without any luck.

i am trying to run this code

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'
Asif Khan
  • 56
  • 8
  • have you seen this https://github.com/matplotlib/matplotlib/issues/5633/ – Radan Nov 15 '17 at 13:41
  • yes, he is using Anaconda but i am not using anaconda – Asif Khan Nov 15 '17 at 13:44
  • 1
    have you tried this one? https://stackoverflow.com/questions/45103248/importerror-no-module-named-matplotlib-externals – Radan Nov 15 '17 at 13:50
  • i am not using seaborn library , now install it but problem not solved – Asif Khan Nov 15 '17 at 14:04
  • Can you provide the full error log? – Pierre de Buyl Nov 15 '17 at 14:04
  • 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 from mpl_toolkits.mplot3d import Axes3D, axes3d File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/__init__.py", line 4, in from matplotlib.externals import six ImportError: No module named 'matplotlib.externals' – Asif Khan Nov 15 '17 at 14:05
  • walk through your 2 links many time, but problem not solved – Asif Khan Nov 15 '17 at 14:07
  • Place it in the original question, please, it is unreadable in the comments. – Pierre de Buyl Nov 15 '17 at 14:07
  • Did you remove the system package for matplotlib? `sudo apt-get remove python3-matplotlib` ? – Pierre de Buyl Nov 15 '17 at 14:08
  • i remove it using pip install it following command sudo pip install matplotlib --upgrade --ignore-installed six – Asif Khan Nov 15 '17 at 14:11

1 Answers1

0

Execute:

sudo apt-get remove python3-matplotlib

This will remove the version that is located in /usr/lib/python3/dist-packages/ according to your error log.

Pierre de Buyl
  • 7,074
  • 2
  • 16
  • 22
  • thanks it work, @Pierre de Buy!, but now reached following warning /usr/local/lib/python3.5/dist-packages/pandas/core/computation/__init__.py:18: UserWarning: The installed version of numexpr 2.4.3 is not supported in pandas and will be not be used The minimum supported version is 2.4.6 ver=ver, min_ver=_MIN_NUMEXPR_VERSION), UserWarning) – Asif Khan Nov 15 '17 at 14:23
  • why pandas package conflict with numexpr 2.4.3 ?? – Asif Khan Nov 15 '17 at 14:25
  • I don't know the reason of the conflict, but the recipe is similar. Try to uninstall pandas with `sudo apt-get remove python3-pandas` and install via pip instead. It should download the up-to-date numexpr as well. – Pierre de Buyl Nov 15 '17 at 14:27