Python Forum

Full Version: Matplotlib bar chart
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have a problem trying to display a bar chart.
Using OpenCV "reduce" method I obtain an array (like an histogram). This method computes the vertical projection so it's basically an histogram.

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

image = cv.imread("image-test.png",cv.IMREAD_GRAYSCALE)
histo = cv.reduce(image,0,cv.REDUCE_AVG)
imageWidth = histo.shape[1]
Now I want to display the image and the array (as a bar chart).
#Show image
plt.subplot(221)
plt.imshow(image,cmap = 'gray')
plt.title('Image')
plt.xticks([]), plt.yticks([])

#Show histogram
plt.subplot(222)
plt.title('Histo')
plt.plot(histo)
X-axis is 0 to "imageWidth-1" and Y-axis is 0 to 255 as the image is grayscale and "reduce" is computed as average.

The image is shown as expected but the histogram not.