Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. def draw_plots(P, m, n, x, y, sample):
  2.     def draw_plot(plot, x, values1, values2):
  3.         x_plot = plt.subplot(111)
  4.         x_plot.bar([x_i - 0.2 for x_i in x], values1, width=0.2, color='green', fill=True)
  5.         x_plot.bar(x, values2, width=0.2, color='red', fill=True)
  6.  
  7.     Px = [sum(P_j) for P_j in P]
  8.     Py = [sum([P[i][j] for i in range(m)]) for j in range(n)]
  9.  
  10.     Px_sample = [0] * m
  11.     Py_sample = [0] * n
  12.  
  13.     x_sample = sorted([z[0] for z in sample])
  14.     for i in range(m):
  15.         Px_sample[i] = x_sample.count(x[i]) / len(x_sample)
  16.  
  17.     y_sample = sorted([z[1] for z in sample])
  18.     for i in range(n):
  19.         Py_sample[i] = y_sample.count(y[i]) / len(y_sample)
  20.  
  21.     plt.figure(1)
  22.     draw_plot(plt, x, Px, Px_sample)
  23.     plt.figure(2)
  24.     draw_plot(plt, y, Py, Py_sample)
  25.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement