Skip to content

Instantly share code, notes, and snippets.

@aita
Created June 30, 2013 12:44
Show Gist options
  • Select an option

  • Save aita/5895027 to your computer and use it in GitHub Desktop.

Select an option

Save aita/5895027 to your computer and use it in GitHub Desktop.
import csv
import math
import numpy as np
import matplotlib.pyplot as plt
from collections import defaultdict
DATA = [
(400, 60),
(15, 30),
(480, 365),
(993, 190),
(600, 136),
(150, 15),
(115, 37),
(50, 100),
(0, 170),
(130, 70),
(3000, 783),
(500, 560),
(200, 50),
(55, 35),
(2200, 595),
(1, 200),
(900, 300),
(1000, 356),
(450, 155),
(400, 250)
]
# 度数分布表
data = [x[1] for x in DATA]
table = {x:0 for x in range(max(data)/160+1)}
for d in DATA:
x = d[1]
table[x/160] += 1
x = 0
for k, v in table.items():
low, upper = k*160, (k+1)*160
l = len(DATA)
p = float(v)/l * 100
x += p
print "%s~%s: %s, %s, %s, %s" % (low, upper, (low+upper)/2, v, p, x)
# ヒストグラム
bins = int(math.sqrt(len(DATA))+1)
print bins
plt.hist([x[1] for x in DATA], bins=bins)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment