I want to create a histogram using Python and Matplotlib from the values in an array not on the count of the values in the array. For example:-
X = [0,0,0,1,10,5,0,0,5]
If I use the below code
n, bins, patches = plt.hist(X)
plt.show()
I get this histogram
This is counting the number of occurrences and creating the histogram. The output should be like this:- Expected Plot
Looks like you want a bar graph rather than a histogram. Note that a histogram is:
An accurate representation of the distribution of numerical data
It differs from a bar graph, in the sense that a bar graph relates two variables, but a histogram relates only one.
For plotting a bar graph you could use matplotlib.pyplot.bar
:
X = [0,0,0,1,10,5,0,0,5]
import matplotlib.pyplot as plt
plt.bar(range(len(X)), X)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With