Suppose I have two lists:
x1 = [1,2,3,4,5,6,7,8,1,10]
x2 = [2,4,2,1,1,1,1,1,2,1]
Here, each index i
of the list is a point in time, and x2[i]
denotes the number of times (frequency) than x1[i]
was observed was observed at time i
. Note also that x1[0] = 1 and x1[8] = 1, with a total frequency of 4 (= x2[0] + x2[8]).
How do I efficiently turn this into a histogram? The easy way is below, but this is probably inefficient (creating third object and looping) and would hurt me since I have gigantic data.
import numpy as np
import matplotlib.pyplot as plt
x3 = []
for i in range(10):
for j in range(x2[i]):
x3.append(i)
hist, bins = np.histogram(x1,bins = 10)
width = 0.7*(bins[1]-bins[0])
center = (bins[:-1]+bins[1:])/2
plt.bar(center, hist, align = 'center', width = width)
plt.show()