我正在尝试练习python图像像素颜色直方图
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('image.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
hist = cv2.calcHist([gray], [0], None, [256], [0, 256])
plt.bar(range(1,257), hist)
plt.show()
它给出了一个错误
Traceback (most recent call last):
File "C:/Users/jmu/Desktop/123.py", line 15, in
plt.bar(range(1,257), hist)
File "C:\Users\jmu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\matplotlib\pyplot.py", line 2457, in bar
**({"data": data} if data is not None else {}), **kwargs)
File "C:\Users\jmu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\matplotlib\__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
File "C:\Users\jmu\AppData\Local\Programs\Pyt