[英]Opening an image in python with matplotlib
I am trying to open an image in python with matplotlib using this code: 我正在尝试使用以下代码在带有matplotlib的python中打开图像:
import cv2
from matplotlib import pyplot as plt
img=cv2.imread('d:\google.jpg')
plt.imshow(img)
plt.show()
there is an image in d:\\ which is google logo. d:\\中有一张图片,是Google徽标。
after that I am trying to run the code and I got this error message: 之后,我尝试运行代码,并收到以下错误消息:
Traceback (most recent call last):
File "C:/Users/�����/PycharmProjects/untitled4/h.py", line 2, in <module>
from matplotlib import pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 71, in <module>
from matplotlib.backends import pylab_setup
File "C:\Python27\lib\site-packages\matplotlib\backends\__init__.py", line 16, in <module>
line for line in traceback.format_stack()
File "C:\Python27\lib\site-packages\matplotlib\backends\__init__.py", line 18, in <genexpr>
if not line.startswith(' File "<frozen importlib._bootstrap'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf9 in position 17: ordinal not in range(128)
Please help :) 请帮忙 :)
You code works for me. 您的代码对我有用。
Looking at your stack trace, the error is happening within the matplotlib
package. 查看您的堆栈跟踪,该错误发生在
matplotlib
软件包中。
You should re-install your package, and see if the error goes away. 您应该重新安装软件包,然后查看错误是否消失。
Try: 尝试:
pip install --upgrade --force-reinstall matplotlib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.