All the matplotlib examples with hist()
generate a data set, provide the data set to the hist
function with some bins (possibly non-uniformly spaced) and the function automatically calculates and then plots the histogram.
I already have histogram data and I simply want to plot it, how can I do that?! For example, I have the bins (half open ranges are denoted by the square and curved bracket notation),
[0, 1) 0
[1, 2) 3
[2, 3) 8
[3, 4) 6
[4, 5) 2
[5, 6) 3
[6, 7) 1
[7, 8) 0
The towers or bars of a histogram are called bins. The height of each bin shows how many values from that data fall into that range. The default value of the number of bins to be created in a histogram is 10.
A histogram displays numerical data by grouping data into "bins" of equal width. Each bin is plotted as a bar whose height corresponds to how many data points are in that bin. Bins are also sometimes called "intervals", "classes", or "buckets".
Choose between 5 and 20 bins. The larger the data set, the more likely you'll want a large number of bins. For example, a set of 12 data pieces might warrant 5 bins but a set of 1000 numbers will probably be more useful with 20 bins. The exact number of bins is usually a judgment call.
Perhaps the weight parameter would be of help in your problem.
import matplotlib.pyplot as plt
a= [1,2,3,4,5,6,7,8,9]
b= [5,3,4,5,3,2,1,2,3]
plt.hist(a,9, weights=b)
plt.show()
Or, as tcaswell said, you could just make a bar plot and change the x-axis.
Using matplotlib how could I plot a histogram with given data in python
Is a link.
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