我想在不同的图中绘制两个不同的直方图,但在同一窗口中打开。使用以下代码,我在同一个图中得到两个直方图。我无法获得带有子图的直方图,不知道我哪里出错了。
from matplotlib import pyplot as plt
img = cv2.imread(f)
img1 = cv2.imread('compressed_' + f)
color = ('b', 'g', 'r')
for i, col in enumerate(color):
histr = cv2.calcHist([img], [i], None, [256], [0, 256])
hist = cv2.calcHist([img1], [i], None, [256], [0, 256])
plt.plot(histr, color=col)
plt.plot(hist, color=col)
plt.xlim([0, 256])
plt.title('Original image')
plt.show()
相关分类