Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. def draw(data, param=[1., 2.], title='LALALA', data_type='Россия', limit=None):
  2.     plt.rcParams["figure.figsize"]=15,10
  3.     mean, std, count = [], [], []
  4.     for day in range(max(len(i) for i in data)):
  5.         arr = []
  6.         for city in data:
  7.             try:
  8.                 arr.append(city[day])
  9.             except:
  10.                 pass
  11.         mean.append(np.mean(arr))
  12.         std.append(np.std(arr))
  13.         count.append(len(arr))
  14.  
  15.     mean = np.array(mean)
  16.     std = np.array(std)
  17.     count = np.array(count)
  18.     xasix = range(max(len(i) for i in data))
  19.    
  20.     fig = plt.figure(figsize=(20, 10))
  21.     gs = gridspec.GridSpec(2, 1, height_ratios=[4, 1])
  22.    
  23.     ax0 = plt.subplot(gs[0])
  24.     ax0.grid()
  25.     ax0.plot(xasix[:len(data[0])], data[0], 'o-', color="k", label=data_type)
  26.     ax0.fill_between(xasix, mean - 2 * std, mean + 2 * std, alpha=0.1, color="b", label="Доверительный интервал 95%")
  27.     ax0.fill_between(xasix, mean - std, mean + std, alpha=0.3, color="y", label="Доверительный интервал 68%")
  28.     ax0.fill_between(xasix, mean - 0.32 * std, mean + 0.32 *  std, alpha=0.3, color="r", label="Доверительный интервал 25%")
  29.     ax0.plot(xasix, mean, 'o-', color="r", label="Математическое ожидание")
  30.     ax0.legend(loc='best', prop={'size': 16})
  31.     matplotlib.rc('xtick', labelsize=18)
  32.     matplotlib.rc('ytick', labelsize=18)
  33.     plt.ylabel("Количесво заболевших", fontsize=18)
  34. #     ax0.axes.get_xaxis().set_visible(False)
  35. #     plt.subplot(212)
  36.     ax1 = plt.subplot(gs[1])
  37.     ax1.grid()
  38.     ax1.plot(xasix, count, 'o-', color="k", label="Математическое ожидание")
  39.     plt.xlabel('День эпидемии', fontsize=18)
  40.     plt.ylabel("Количесво наблюдений", fontsize=18)
  41.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement