Created
January 15, 2016 13:56
-
-
Save HeinrichHartmann/38f4f2a281e2aebe547e to your computer and use it in GitHub Desktop.
Simple (inefficient) example of how to create a histogram with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
import numpy as np | |
X = np.genfromtxt("DataSets/RequestRates.csv", delimiter=",")[:,1] | |
bins = [500, 700, 800, 900, 1000, 1500, 1800, 2000, 2200] | |
bin_count = len(bins) - 1 | |
sample_counts = [0] * bin_count | |
for x in X: | |
for i in range(bin_count): | |
if (bins[i] <= x) and (x < bins[i + 1]): | |
sample_counts[i] += 1 | |
bin_widths = [ float(bins[i] - bins[i-1]) for i in range(1, bin_count) ] | |
bin_heights = [ count/width for count, width in zip(sample_counts,bin_widths) ] | |
plt.bar(bins[:bin_count-1], width=bin_widths, height=bin_heights); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment