Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Mon Oct 22 12:10:05 2018
- @author: Raul Sanchez-Vazquez
- """
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- from scipy import stats
- np.random.seed(seed=42)
- size = 1000000
- sample_norm_1 = np.array(
- list(stats.norm.rvs(loc=0, scale=1, size=size)) + [-10, 10]
- )
- sample_norm_2 = np.hstack([
- list(stats.norm.rvs(loc=-1, scale=.25, size=int(size * .75))),
- list(stats.norm.rvs(loc=1, scale=.91, size=int(size * .25))),
- list([-10, 10])
- ])
- sample_norm_3 = sample_norm_2 * -1
- range_1 = [sample_norm_1.min(), sample_norm_1.max()]
- range_2 = [sample_norm_2.min(), sample_norm_2.max()]
- range_3 = [sample_norm_3.min(), sample_norm_3.max()]
- std_1 = sample_norm_1.std()
- std_2 = sample_norm_2.std()
- std_3 = sample_norm_3.std()
- mean_1 = sample_norm_1.mean()
- mean_2 = sample_norm_2.mean()
- mean_3 = sample_norm_3.mean()
- print('ranges:', range_1, range_2, range_3)
- print('std:', std_1, std_2, std_3)
- print('std:', mean_1, mean_2, mean_3)
- fig, ax = plt.subplots(3, 1, figsize=(8, 8))
- pd.Series(sample_norm_1).plot(
- kind='hist', alpha=.5, ax=ax[0], grid=True, color='gray', bins=100,
- title='Dataset 1 (range: %s, mean: %s, std: %s' % (range_1, mean_1, std_1))
- pd.Series(sample_norm_2).plot(
- kind='hist', alpha=.5, ax=ax[1], color='red', bins=100,
- title='Dataset 2 (range: %s, mean: %s, std: %s' % (range_2, mean_2, std_2))
- pd.Series(sample_norm_3).plot(
- kind='hist', alpha=.5, ax=ax[2], color='blue', bins=100,
- title='Dataset 3 (range: %s, mean: %s, std: %s' % (range_3, mean_3, std_3))
- fig.set_tight_layout('tight')
Add Comment
Please, Sign In to add comment