Advertisement
Guest User

Исходники генератора явки

a guest
Apr 3rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. %matplotlib inline
  2. import numpy as np
  3. from matplotlib import pyplot as plt
  4. import seaborn as sns
  5. import random
  6.  
  7. def draw_turnout_distribution_uniform(sizes, bins, title):
  8.     sizes_in_people = np.floor(sizes)
  9.     turnout_in_people = np.array([random.randint(0, voters) for voters in sizes_in_people])
  10.     turnout_fraction = turnout_in_people / sizes_in_people
  11.  
  12.     plt.figure(figsize=(16,8), dpi=100)
  13.     axis = plt.gca()
  14.     axis.set_facecolor('#e8e8e8')
  15.     plt.grid(True)
  16.     axis.set_axisbelow(True)
  17.     axis.grid(color='#ffffff')
  18.     # axis.tick_params(axis='x', grid_color='#ffffff')
  19.     plt.hist(turnout_fraction, bins=bins, range=(0, 1.0))
  20.     plt.xticks([0.0, 1.0, 1./2,
  21.                 1./3, 2./3,
  22.                 1./4, 3./4,
  23.                 1./5, 2./5, 3./5, 4./5,
  24.                 1./6, 5./6,
  25.                 1./7, 2./7, 3./7, 4./7, 5./7, 6./7,
  26.                 1./8, 3./8, 5./8, 7./8,
  27.                 1./9, 2./9, 4./9, 5./9, 7./9, 8./9,
  28.                 1./10, 3./10, 7./10, 9./10],
  29.                ["0", "1", "1/2",
  30.                 "1/3", "2/3",
  31.                 "1/4", "3/4",
  32.                 "1/5", "2/5", "3/5", "4/5",
  33.                 "1/6", "5/6",
  34.                 "1/7", "2/7", "3/7", "4/7", "5/7", "6/7",
  35.                 "1/8", "3/8", "5/8", "7/8",
  36.                 "1/9", "2/9", "4/9", "5/9", "7/9", "8/9",
  37.                 "1/10", "3/10", "7/10", "9/10"],
  38.                rotation=90)
  39.     plt.xlim((0, 1.0))
  40.     plt.xlabel("Явка")
  41.     plt.ylabel("Число УИКов с такой явкой")
  42.     plt.title("Равномерное распределение явки по числу УИКов, %s" % title);
  43.  
  44. N_POINTS = 50000
  45. sizes = np.random.uniform(1000, 2000, N_POINTS)
  46.  
  47. draw_turnout_distribution_uniform(sizes, 1000, "участки uniform(1000, 2000), явка uniform(0, 100%)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement