Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import ceil
- from scipy.stats import norm
- from scipy import stats
- def plot_normal(df, sub_col):
- """ Plot QQ-plot alongside histogram."""
- length = ceil(len(sub_col)/2)
- fig, axes = plt.subplots(length, 4, figsize=(20,17))
- axes = axes.ravel()
- index = 0
- for col in sub_col:
- (mu, sigma) = norm.fit(df[col])
- (a,b) = stats.probplot(df[col], sparams=(mu, sigma)) # QQ plot
- axes[index].plot(*a, color='#014d64', linewidth=5)
- (x_min, x_max) = axes[index].get_xlim()
- x_dots = np.arange(x_min, x_max)
- y_dots = b[0]*x_dots + b[1]
- axes[index].plot(x_dots, y_dots, color='#7c260b')
- axes[index].set_title('QQ Plot', fontsize='large')
- axes[index].set_xlabel('Theoretical Quantiles')
- axes[index].set_ylabel('Ordered Values')
- index += 1
- sns.distplot(df[col], ax=axes[index], kde=True, color='#c7e1e8',
- kde_kws={'color':'#014d64','label':'KDE'},
- fit=norm, fit_kws={'color':'#7c260b','label':'NORMAL'}) # distribution plot
- axes[index].legend(loc='best')
- axes[index].set_title('Histogram', fontsize='large')
- index += 1
Add Comment
Please, Sign In to add comment