Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Histogram from data which is already binned, I have bins and frequency values

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
like image 238
Daniel Farrell Avatar asked Jun 21 '13 14:06

Daniel Farrell


People also ask

What is the default value for bins in a histogram?

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.

How do bins work in histograms?

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".

How many bins should a histogram have?

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.


1 Answers

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.

like image 109
user e to the power of 2pi Avatar answered Sep 16 '22 20:09

user e to the power of 2pi