Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matplotlib bar chart
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question I’m trying to create a Power BI Matplotlib quadrant chart and I’m a little stumped. Nidwolff 1 435 Mar-04-2024, 06:07 AM
Last Post: Danishhafeez
  Rename labels of a bar chart Matplotlib smalatray 1 4,338 Jul-01-2020, 01:48 AM
Last Post: hussainmujtaba
  Spacing pie chart colours evenly in matplotlib? Giovanni_diJacopo 1 3,277 Jul-12-2019, 12:31 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020