Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %matplotlib inline
- import numpy as np
- from matplotlib import pyplot as plt
- import seaborn as sns
- import random
- def draw_turnout_distribution_uniform(sizes, bins, title):
- sizes_in_people = np.floor(sizes)
- turnout_in_people = np.array([random.randint(0, voters) for voters in sizes_in_people])
- turnout_fraction = turnout_in_people / sizes_in_people
- plt.figure(figsize=(16,8), dpi=100)
- axis = plt.gca()
- axis.set_facecolor('#e8e8e8')
- plt.grid(True)
- axis.set_axisbelow(True)
- axis.grid(color='#ffffff')
- # axis.tick_params(axis='x', grid_color='#ffffff')
- plt.hist(turnout_fraction, bins=bins, range=(0, 1.0))
- plt.xticks([0.0, 1.0, 1./2,
- 1./3, 2./3,
- 1./4, 3./4,
- 1./5, 2./5, 3./5, 4./5,
- 1./6, 5./6,
- 1./7, 2./7, 3./7, 4./7, 5./7, 6./7,
- 1./8, 3./8, 5./8, 7./8,
- 1./9, 2./9, 4./9, 5./9, 7./9, 8./9,
- 1./10, 3./10, 7./10, 9./10],
- ["0", "1", "1/2",
- "1/3", "2/3",
- "1/4", "3/4",
- "1/5", "2/5", "3/5", "4/5",
- "1/6", "5/6",
- "1/7", "2/7", "3/7", "4/7", "5/7", "6/7",
- "1/8", "3/8", "5/8", "7/8",
- "1/9", "2/9", "4/9", "5/9", "7/9", "8/9",
- "1/10", "3/10", "7/10", "9/10"],
- rotation=90)
- plt.xlim((0, 1.0))
- plt.xlabel("Явка")
- plt.ylabel("Число УИКов с такой явкой")
- plt.title("Равномерное распределение явки по числу УИКов, %s" % title);
- N_POINTS = 50000
- sizes = np.random.uniform(1000, 2000, N_POINTS)
- draw_turnout_distribution_uniform(sizes, 1000, "участки uniform(1000, 2000), явка uniform(0, 100%)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement