I have a list of tuples as follows:
A=[(122208102.23250552, 34), (164096757.6449624, 4), (212275562.3177331, 72), (499344188.7213493, 240), (515347294.02090293, 2), (614044718.1056056, 4), (623878472.271997, 37), (1050993427.1862154, 2), (1885818969.4904015, 106), (2718942354.402217, 539), (2784838407.8050084, 23), (3996685731.144668, 26), (4540461526.048465, 1), (7019400139.695788, 2), (8079788636.830896, 2), (8847080928.7053, 2), (11989470404.794186, 104), (18560941417.034264, 782), (1130056089748.5376, 518), (1404106338920.4468, 415), (1498994364112.208, 93)]
And here is the bin array corresponding to x coordinates:
bins = np.array(np.logspace(8.00, 12.40, 12))
Now I want to create a histogram whose x coordinate is the first elements of tuples in the A array and whose y coordinate is the frequency of those values represented in the second elements of tuples in the A array. I know that I can separate them through:
x, y = zip(*A)
And then use the following line of code to plot the histogram:
import matplotlib.pyplot as plt
plt.hist(x, bins=bins, density=None, stacked=None, rwidth=0.96, color='blue', log=False, histtype='step', weights=weights)
But the problem is that I don't know how to calculate the weights from the second elements of the tuples numerically. Mathematically one would add up all the second-elements corresponding to those x's that fall in each bin and then divide that by the total number of second-elements in the list.