I'm doing a histogram for an image in numpy ndarray form. I would like to plot all the pixel values larger than a given value in the last bar of the histogram. For example, if the actual range of my data is 0-10 and the range I would like to plot for is 0-7. Then all values larger than 7 will go into the last bar in my histogram, so that my histogram does not have bars for 8,9,10. Instead, all occurrences of 8, 9, 10 should go to my last bar, which is 7.
Any idea how to do this? Thanks everyone!
CodePudding user response:
CodePudding user response:
One way to solve this would be to create a second numpy ndarray, then iterate through the original array, and copy over each value, except for the 8,9 or 10, those would then be copied over as 7. It would look roughly like this:
arraycopy = n.array([]);
for dataPoint in image array:
if dataPoint> 7:
dataPoint = 7
arraycopy.append(dataPoint)
Then you simply plot arraycopy