iT邦幫忙

0

[Python] show distribution

def show_dis(x):
    
    plt.figure(figsize=(15,15))

    ax1= plt.subplot(331)
    ax1.set_title('Normal')
    sns.distplot(x, kde=True, fit=stats.norm ,ax = ax1)
    ax2= plt.subplot(332)
    ax2.set_title('Log Normal')
    sns.distplot(x, kde=False, fit=stats.lognorm ,ax = ax2)
    ax3 = plt.subplot(333)
    ax3.set_title('Johnson SU')
    sns.distplot(x, kde=True, fit=stats.johnsonsu ,ax = ax3)
    
    x_log = np.log10(x - x.min() +1 )
    print("{}".format(x_log.isna().sum()))
    ax4= plt.subplot(334)
    ax4.set_title('Normal (x_log)')
    sns.distplot(x_log, kde=True, fit=stats.norm ,ax = ax4)
    ax5= plt.subplot(335)
    ax5.set_title('Log Normal (x_log)')
    sns.distplot(x_log, kde=False, fit=stats.lognorm ,ax = ax5)
    ax6 = plt.subplot(336)
    ax6.set_title('Johnson SU (x_log)')
    sns.distplot(x_log, kde=True, fit=stats.johnsonsu ,ax = ax6)
        
    (mu, sigma) = norm.fit(x)
    print( '\n mu = {:.2f} and sigma = {:.2f}\n'.format(mu, sigma))
    
    #Get also the QQ-plot
    ax7= plt.subplot(313)
    res = stats.probplot(x, plot=ax7)
    
    plt.tight_layout()
    plt.show()

尚未有邦友留言

立即登入留言