From 3c745606e9494917763313e821e3722d010e2e97 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Fri, 22 Jul 2022 16:40:36 +0800 Subject: refactor: Rename files Signed-off-by: KunoiSayami --- expt_normal_distribution.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 expt_normal_distribution.py (limited to 'expt_normal_distribution.py') diff --git a/expt_normal_distribution.py b/expt_normal_distribution.py new file mode 100755 index 0000000..272b9b6 --- /dev/null +++ b/expt_normal_distribution.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.ticker import PercentFormatter + + +def function_pdf(element: list[int]): + plt.hist(element, bins=500, histtype='step') + plt.show() + + +def function_cdf(element: list[int]): + plt.hist(element, bins=500, cumulative=True, histtype='step') + plt.show() + + +def function_1000_cdf(element: list[int]): + plt.hist(element, bins=250, histtype='step', label='x', cumulative=True, + weights=np.ones(len(element)) / len(element)) + plt.hist(element[:1000], bins=100, histtype='step', label='y', cumulative=True, weights=np.ones(1000) / 1000) + plt.gca().yaxis.set_major_formatter(PercentFormatter(1)) + plt.show() + + +def normal_distribution() -> list[int]: + with open('normal_distribution.txt') as fin: + context = fin.read() + return list(map(int, context.splitlines())) + + +if __name__ == '__main__': + elements = normal_distribution() + function_pdf(elements) + function_cdf(elements) + function_1000_cdf(elements) -- cgit v1.3.1