From d7fb220e52af97d4102afc91ae4cdd4ff2b284e4 Mon Sep 17 00:00:00 2001 From: Eric Austin Barber Date: Sat, 14 Sep 2019 03:01:04 -0400 Subject: [PATCH] Create python3_glyph.py --- python3_glyphs.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 python3_glyphs.py diff --git a/python3_glyphs.py b/python3_glyphs.py new file mode 100644 index 0000000..ce99452 --- /dev/null +++ b/python3_glyphs.py @@ -0,0 +1,80 @@ +from random import randint +from statistics import mean,variance,stdev +import numpy as np +import matplotlib.pyplot as plt +from collections import Counter + +def quest_of_one_frog(): + remaining_pad_count = 100 + current_pad = 1 + number_of_hops = 0 + while remaining_pad_count > 0: + hop_to_pad = randint(current_pad,remaining_pad_count) + remaining_pad_count = remaining_pad_count - hop_to_pad + number_of_hops += 1 + return number_of_hops + +def all_quests_in_pond(): + number_of_quests = 100 + hop_count_list = [] + + for i in range(0,number_of_quests): + hop_count_list.append(quest_of_one_frog()) + + return hop_count_list, mean(hop_count_list), round(variance(hop_count_list),3) , round(stdev(hop_count_list),3) + +def all_ponds_in_forest(): + + list_means = [] + list_variance = [] + list_stdev = [] + list_pond = [] + list_hops = [] + + result_counts = [] + + pond_number = 0 + number_of_ponds = 10 + + for pond in range(0,number_of_ponds): + + hop_count_list, pond_mean , pond_variance , pond_stdev = all_quests_in_pond() + + list_hops.extend(hop_count_list) + + list_means.append(pond_mean) + list_variance.append(pond_variance) + list_stdev.append(pond_stdev) + list_pond.append(pond_number) + + pond_number += 1 + + return list_hops, list_pond , list_means , list_stdev , list_variance + +def main(): + + list_hops, list_pond , list_means , list_stdev , list_variance = all_ponds_in_forest() + + hist_dict = Counter(list_hops) + + fig = plt.figure() + + ax1 = fig.add_subplot(311) + ax1.plot(list_pond,list_means, color="navy", linewidth=3) + ax1.set_title("Some Graphs and Things") + + ax1.set_ylabel('Average Hops') + + ax2 = fig.add_subplot(312, sharex=ax1) + ax2.plot(list_pond,list_variance, color="green", linewidth=3) + ax2.set_ylabel('Variance in Hops') + + ax3 = fig.add_subplot(313) + ax3.bar(hist_dict.keys(), hist_dict.values(), color="gray") + ax3.set_ylabel(f'Histogram:\n {len(list_hops)} Frogs') + + plt.show() + return + +if __name__ == "__main__": + main()