Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib: ImportError: cannot import name 'pyplot'

I have matplotlib lib installed using pip but when I run this code it gives me this error:

shar@shar-Lenovo-G50-30 ~ $ python3 opencv.py
Traceback (most recent call last):
  File "opencv.py", line 3, in <module>
    from matplotlib import pyplot as plt
ImportError: cannot import name 'pyplot'

My code is:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img1 = cv2.imread('/home/shar/home.jpg',0)  # queryImage
img2 = cv2.imread('/home/shar/home2.jpg',0) # trainImage

# Initiate SIFT detector
orb = cv2.ORB()

# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

# Match descriptors.
matches = bf.match(des1,des2)

# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)

# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)

plt.imshow(img3),plt.show()

I also tried to install matplotlib from source and that still give me the error.

like image 324
shar Avatar asked Jul 25 '15 16:07

shar


1 Answers

Make sure you don't have any file names matplotlib.py that you have created if any then rename or delete that file. It worked for me

like image 103
Gyanendra Maurya Avatar answered Nov 15 '22 01:11

Gyanendra Maurya