I like to plot my histograms like this:
data = [-0.5, 0.5, 0.5, 0.5,
1.5, 2.1, 2.2, 2.3, 2.4, 2.5, 3.1, 3.2]
plt.hist(data, bins=5, range=[-1, 4], histtype='step')
Now, when I have somehow large input data (larger than my memory), I need to fill the histogram chunk by chunk. E.g. like this:
H, bins = np.histogram([], bins=5, range=[-1, 4])
for data in a_lot_of_input_files:
H += np.histogram(data, bins=5, range=[-1, 4])[0]
But the question is always, "How do I plot this H
again, so it looks just like the previous matplotlib version.
The solution I came up with, looks like this:
plt.plot(bins, np.insert(H, 0, H[0]), '-', drawstyle='steps')
However, neither looks the result identical, nor does it feel very nice to create a copy of H
for plotting it.
Is there some elegant solution I am missing? (I did not yet try to use plt.bar
, because the bar-graphs don't work nicely, when one wants to compare histograms)