Guest User

Untitled

a guest
Oct 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Oct 22 12:10:05 2018
  5.  
  6. @author: Raul Sanchez-Vazquez
  7. """
  8.  
  9. import matplotlib.pyplot as plt
  10. import numpy as np
  11. import pandas as pd
  12. from scipy import stats
  13.  
  14. np.random.seed(seed=42)
  15.  
  16. size = 1000000
  17. sample_norm_1 = np.array(
  18. list(stats.norm.rvs(loc=0, scale=1, size=size)) + [-10, 10]
  19. )
  20.  
  21. sample_norm_2 = np.hstack([
  22. list(stats.norm.rvs(loc=-1, scale=.25, size=int(size * .75))),
  23. list(stats.norm.rvs(loc=1, scale=.91, size=int(size * .25))),
  24. list([-10, 10])
  25. ])
  26.  
  27. sample_norm_3 = sample_norm_2 * -1
  28.  
  29. range_1 = [sample_norm_1.min(), sample_norm_1.max()]
  30. range_2 = [sample_norm_2.min(), sample_norm_2.max()]
  31. range_3 = [sample_norm_3.min(), sample_norm_3.max()]
  32.  
  33. std_1 = sample_norm_1.std()
  34. std_2 = sample_norm_2.std()
  35. std_3 = sample_norm_3.std()
  36.  
  37. mean_1 = sample_norm_1.mean()
  38. mean_2 = sample_norm_2.mean()
  39. mean_3 = sample_norm_3.mean()
  40.  
  41. print('ranges:', range_1, range_2, range_3)
  42. print('std:', std_1, std_2, std_3)
  43. print('std:', mean_1, mean_2, mean_3)
  44.  
  45. fig, ax = plt.subplots(3, 1, figsize=(8, 8))
  46. pd.Series(sample_norm_1).plot(
  47. kind='hist', alpha=.5, ax=ax[0], grid=True, color='gray', bins=100,
  48. title='Dataset 1 (range: %s, mean: %s, std: %s' % (range_1, mean_1, std_1))
  49. pd.Series(sample_norm_2).plot(
  50. kind='hist', alpha=.5, ax=ax[1], color='red', bins=100,
  51. title='Dataset 2 (range: %s, mean: %s, std: %s' % (range_2, mean_2, std_2))
  52. pd.Series(sample_norm_3).plot(
  53. kind='hist', alpha=.5, ax=ax[2], color='blue', bins=100,
  54. title='Dataset 3 (range: %s, mean: %s, std: %s' % (range_3, mean_3, std_3))
  55. fig.set_tight_layout('tight')
Add Comment
Please, Sign In to add comment