当前位置: 首页>>代码示例>>Python>>正文


Python C2_8_mystyle类代码示例

本文整理汇总了Python中C2_8_mystyle的典型用法代码示例。如果您正苦于以下问题:Python C2_8_mystyle类的具体用法?Python C2_8_mystyle怎么用?Python C2_8_mystyle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了C2_8_mystyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scatterplot

def scatterplot():
    '''Fancy scatterplots, using the package "seaborn" '''
    import seaborn as sns
    
    df = sns.load_dataset("iris")
    sns.pairplot(df, hue="species", size=2.5)    
    C2_8_mystyle.printout_plain('multiScatterplot.png')
开发者ID:akansal1,项目名称:statsintro_python,代码行数:7,代码来源:C4_3_basicPrinciples.py

示例2: showResults

def showResults(challenger_data, model):
    ''' Show the original data, and the resulting logit-fit'''
    
    # First plot the original data
    plt.figure()
    sns.set_context('poster')
    sns.set_style('whitegrid')
    np.set_printoptions(precision=3, suppress=True)
    
    plt.scatter(challenger_data[:, 0], challenger_data[:, 1], s=75, color="k",
                alpha=0.5)
    plt.yticks([0, 1])
    plt.ylabel("Damage Incident?")
    plt.xlabel("Outside temperature (Fahrenheit)")
    plt.title("Defects of the Space Shuttle O-Rings vs temperature")
    plt.xlim(50, 85)
    
    # Plot the fit
    x = np.arange(50, 85)
    alpha = model.params[0]
    beta = model.params[1]
    y = logistic(x, beta, alpha)
    
    plt.hold(True)
    plt.plot(x,y,'r')
    outFile = 'ChallengerPlain.png'
    C2_8_mystyle.printout_plain(outFile, outDir='..\Images')
    plt.show()
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:28,代码来源:C13_2_logit.py

示例3: generatedata

def generatedata():
    ''' Generate and show the data '''
    x = np.linspace(-5,5,101)
    (X,Y) = np.meshgrid(x,x)
    
    # To get reproducable values, I provide a seed value
    np.random.seed(987654321)   
    
    Z = -5 + 3*X-0.5*Y+np.random.randn(np.shape(X)[0], np.shape(X)[1])
    
    # Plot the figure
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(X,Y,Z, cmap=cm.afmhot, rstride=2, cstride=2, 
        linewidth=0, antialiased=False)
    ax.view_init(20,-120)
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    fig.colorbar(surf, shrink=0.6)
    
    outFile = '3dSurface.png'
    C2_8_mystyle.printout_plain(outFile)
    
    
    return (X.flatten(),Y.flatten(),Z.flatten())
开发者ID:akansal1,项目名称:statsintro_python,代码行数:26,代码来源:C11_2_multipleRegression.py

示例4: generateData

def generateData():
    ''' Generate and show the data: a plane in 3D '''
    
    x = np.linspace(-5,5,101)
    (X,Y) = np.meshgrid(x,x)
    
    # To get reproducable values, I provide a seed value
    np.random.seed(987654321)   
    
    Z = -5 + 3*X-0.5*Y+np.random.randn(np.shape(X)[0], np.shape(X)[1])
    
    # Set the color
    myCmap = cm.GnBu_r
    
    # If you want a colormap from seaborn use:
    #from matplotlib.colors import ListedColormap
    #myCmap = ListedColormap(sns.color_palette("Blues", 20))
    
    # Plot the figure
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(X,Y,Z, cmap=myCmap, rstride=2, cstride=2, 
        linewidth=0, antialiased=False)
    ax.view_init(20,-120)
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    fig.colorbar(surf, shrink=0.6)
    
    outFile = '3dSurface.png'
    C2_8_mystyle.printout_plain(outFile)
    
    
    return (X.flatten(),Y.flatten(),Z.flatten())
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:34,代码来源:C12_2_multipleRegression.py

示例5: show_poisson_views

def show_poisson_views():
    """Show different views of a Poisson distribution"""
    
    fig, ax = plt.subplots(3,1)
    
    k = np.arange(25)
    pd = stats.poisson(10)
    C2_8_mystyle.set(12)
    
    ax[0].plot(k, pd.pmf(k),'x-')
    ax[0].set_title('Poisson distribition')
    ax[0].set_xticklabels([])
    ax[0].set_ylabel('PMF (X)')
    
    ax[1].plot(k, pd.cdf(k))
    ax[1].set_xlabel('X')
    ax[1].set_ylabel('CDF (X)')
    
    y = np.linspace(0,1,100)
    ax[2].plot(y, pd.ppf(y))
    ax[2].set_xlabel('X')
    ax[2].set_ylabel('PPF (X)')
    
    plt.tight_layout()
    plt.show()
开发者ID:akansal1,项目名称:statsintro_python,代码行数:25,代码来源:C5_4_distDiscrete.py

示例6: main

def main():
    # Generate dummy data
    x = np.array([-2.1, -1.3, -0.4, 1.9, 5.1, 6.2])
    
    # Define the two plots
    fig, axs = plt.subplots(1,2)
    
    # Generate the left plot
    plot_histogram(axs[0], x)
    
    # Generate the right plot
    explain_KDE(axs[1], x)
    
    # Save and show
    C2_8_mystyle.printout_plain('KDEexplained.png')
    plt.show()
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:16,代码来源:F4_3_kdePrinciple.py

示例7: generate_probplot

def generate_probplot():
    '''Generate a prob-plot for a chi2-distribution of sample data'''
    # Define the skewed distribution
    chi2 = stats.chi2(3)
    
    # Generate the data
    x = np.linspace(0,10, 100)
    y = chi2.pdf(x)
    np.random.seed(12345)
    numData = 100
    data = chi2.rvs(numData)
    
    # Arrange subplots
    sns.set_context('paper')
    sns.set_style('white')
    C2_8_mystyle.set(11)
    fig, axs = plt.subplots(1,2)
    
    # Plot distribution
    axs[0].plot(x,y)
    axs[0].set_xlabel('X')
    axs[0].set_ylabel('PDF(X)')
    axs[0].set_title('chi2(x), k=3')
    sns.set_style('white')
    
    x0, x1 = axs[0].get_xlim()
    y0, y1 = axs[0].get_ylim()
    axs[0].set_aspect((x1-x0)/(y1-y0))
    #sns.despine()
    
    
    # Plot probplot
    plt.axes(axs[1])
    stats.probplot(data, plot=plt)
    
    x0, x1 = axs[1].get_xlim()
    y0, y1 = axs[1].get_ylim()
    axs[1].axhline(0, lw=0.5, ls='--')
    axs[1].axvline(0, lw=0.5, ls='--')
    axs[1].set_aspect((x1-x0)/(y1-y0))
    #sns.despine()
    
    C2_8_mystyle.printout_plain('chi2pp.png')
    
    return(data)
    '''
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:46,代码来源:F7_2_probplotChi2.py

示例8: KS_principle

def KS_principle(inData):
    '''Show the principle of the Kolmogorov-Smirnov test.'''
    
    # CDF of normally distributed data
    nd = stats.norm()
    nd_x = np.linspace(-4, 4, 101)
    nd_y = nd.cdf(nd_x)
    
    # Empirical CDF of the sample data, which range for approximately 0 to 10
    numPts = 50
    lowerLim = 0
    upperLim = 10
    ecdf_x = np.linspace(lowerLim, upperLim, numPts)
    ecdf_y = stats.cumfreq(data, numPts, (lowerLim, upperLim))[0]/len(inData)
    
    #Add zero-point by hand
    ecdf_x = np.hstack((0., ecdf_x))
    ecdf_y = np.hstack((0., ecdf_y))
    
    # Plot the data
    sns.set_style('ticks')
    sns.set_context('poster')
    C2_8_mystyle.set(36)
    
    plt.plot(nd_x, nd_y, 'k--')
    plt.hold(True)
    plt.plot(ecdf_x, ecdf_y, color='k')
    plt.xlabel('X')
    plt.ylabel('Cumulative Probability')
    
    # For the arrow, find the start
    ecdf_startIndex = np.min(np.where(ecdf_x >= 2))
    arrowStart = np.array([ecdf_x[ecdf_startIndex], ecdf_y[ecdf_startIndex]])
    
    nd_startIndex = np.min(np.where(nd_x >= 2))
    arrowEnd = np.array([nd_x[nd_startIndex], nd_y[nd_startIndex]])
    arrowDelta = arrowEnd - arrowStart
    
    plt.arrow(arrowStart[0], arrowStart[1], 0, arrowDelta[1],
              width=0.05, length_includes_head=True, head_length=0.02, head_width=0.2, color='k')
    
    plt.arrow(arrowStart[0], arrowStart[1]+arrowDelta[1], 0, -arrowDelta[1],
              width=0.05, length_includes_head=True, head_length=0.02, head_width=0.2, color='k')
    
    outFile = 'KS_Example.png'
    C2_8_mystyle.printout_plain(outFile)
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:46,代码来源:F7_2_probplotChi2.py

示例9: showChi2

def showChi2():
    '''Utility function to show Chi2 distributions'''
    
    t = frange(0, 8, 0.05)
    Chi2Vals = [1,2,3,5]
    
    for chi2 in Chi2Vals:
        plt.plot(t, stats.chi2.pdf(t, chi2), label='k={0}'.format(chi2))
    plt.legend()
        
    plt.xlim(0,8)
    plt.xlabel('X')
    plt.ylabel('pdf(X)')
    plt.axis('tight')
    
    outFile = 'dist_chi2.png'
    C2_8_mystyle.printout_plain(outFile)
开发者ID:akansal1,项目名称:statsintro_python,代码行数:17,代码来源:C5_6_distContinuous.py

示例10: showExp

def showExp():
    '''Utility function to show exponential distributions'''
    
    t = frange(0, 3, 0.01)
    lambdas = [0.5, 1, 1.5]
    
    for par in lambdas:
        plt.plot(t, stats.expon.pdf(t, 0, par), label='$\lambda={0:3.1f}$'.format(par))
    plt.legend()
        
    plt.xlim(0,3)
    plt.xlabel('X')
    plt.ylabel('pdf(X)')
    plt.axis('tight')
    plt.legend()
        
    outFile = 'dist_exp.png'
    C2_8_mystyle.printout_plain(outFile)
开发者ID:akansal1,项目名称:statsintro_python,代码行数:18,代码来源:C5_6_distContinuous.py

示例11: show_poisson

def show_poisson():
    """Show an example of Poisson distributions"""
    
    # Arbitrarily select 3 lambda values
    lambdas = [1,4,10]
    
    k = np.arange(20)       # generate x-values
    markersize = 8
    for par in lambdas:
        plt.plot(k, stats.poisson.pmf(k, par), 'o--', label='$\lambda={0}$'.format(par))
    
    # Format the plot
    plt.legend()
    plt.title('Poisson distribuition')
    plt.xlabel('X')
    plt.ylabel('P(X)')
    
    # Show and save the plot
    C2_8_mystyle.printout_plain('Poisson_distribution_pmf.png')
开发者ID:akansal1,项目名称:statsintro_python,代码行数:19,代码来源:C5_4_distDiscrete.py

示例12: showF

def showF():
    '''Utility function to show F distributions'''
    
    t = frange(0, 3, 0.01)
    d1s = [1,2,5,100]
    d2s = [1,1,2,100]
    
    for (d1,d2) in zip(d1s,d2s):
        plt.plot(t, stats.f.pdf(t, d1, d2), label='F({0}/{1})'.format(d1,d2))
    plt.legend()
        
    plt.xlim(0,3)
    plt.xlabel('X')
    plt.ylabel('pdf(X)')
    plt.axis('tight')
    plt.legend()
        
    outFile = 'dist_f.png'
    C2_8_mystyle.printout_plain(outFile)
开发者ID:akansal1,项目名称:statsintro_python,代码行数:19,代码来源:C5_6_distContinuous.py

示例13: show3D

def show3D():
    '''Generation of 3D plots'''
    
    # imports specific to the plots in this example
    from matplotlib import cm   # colormaps
    
    # This module is required for 3D plots!
    from mpl_toolkits.mplot3d import Axes3D
    
    # Twice as wide as it is tall.
    fig = plt.figure(figsize=plt.figaspect(0.5))
    
    #---- First subplot
    # Generate the data
    X = np.arange(-5, 5, 0.1)
    Y = np.arange(-5, 5, 0.1)
    X, Y = np.meshgrid(X, Y)
    R = np.sqrt(X**2 + Y**2)
    Z = np.sin(R)
    
    # Note the definition of "projection", required for 3D  plots
    #plt.style.use('ggplot')

    ax = fig.add_subplot(1, 2, 1, projection='3d')
    surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.GnBu,
            linewidth=0, antialiased=False)
    #surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.viridis_r,
            #linewidth=0, antialiased=False)
    ax.set_zlim3d(-1.01, 1.01)
    
    fig.colorbar(surf, shrink=0.5, aspect=10)
    
    #---- Second subplot
    # Get some 3d test-data
    from mpl_toolkits.mplot3d.axes3d import get_test_data
    
    ax = fig.add_subplot(1, 2, 2, projection='3d')
    X, Y, Z = get_test_data(0.05)
    ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

    C2_8_mystyle.printout_plain('3dGraph.png')
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:41,代码来源:C4_3_showData.py

示例14: shifted_normal

def shifted_normal():
    '''PDF and scatter plot'''
    
    # Plot 3 PDFs (Probability density functions) for normal distributions ----------
    
    # Select 3 mean values, and 3 SDs
    myMean = [0,0,0,-2]
    mySD = [0.2,1,5,0.5]
    t = frange(-5,5,0.02)
    
    # Plot the 3 PDFs, using the color-palette "hls"
    with sns.color_palette('hls', 4):
        for mu,sigma in zip(myMean, np.sqrt(mySD)):
            y = stats.norm.pdf(t, mu, sigma)
            plt.plot(t,y, label='$\mu={0}, \; \t\sigma={1:3.1f}$'.format(mu,sigma))
        
    # Format the plot
    plt.legend()
    plt.xlim([-5,5])
    plt.title('Normal Distributions')
    
    # Show the plot, and save the out-file
    outFile = 'Normal_Distribution_PDF.png'
    C2_8_mystyle.printout_plain(outFile)
    
    # Generate random numbers with a normal distribution ------------------------
    myMean = 0
    mySD = 3
    numData = 500
    data = stats.norm.rvs(myMean, mySD, size = numData)
    
    # Plot the data
    plt.scatter(np.arange(len(data)), data)
    
    # Format the plot
    plt.title('Normally distributed data')
    plt.xlim([0,500])
    plt.ylim([-10,10])
    plt.show()
    plt.close()
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:40,代码来源:C6_5_distNormal.py

示例15: doTukey

def doTukey(data, multiComp):    
    '''Do a pairwise comparison, and show the confidence intervals'''
    
    print((multiComp.tukeyhsd().summary()))
    
    # Calculate the p-values:
    res2 = pairwise_tukeyhsd(data['StressReduction'], data['Treatment'])
    df = pd.DataFrame(data)
    numData = len(df)
    numTreatments = len(df.Treatment.unique())
    dof = numData - numTreatments
    
    # Show the group names
    print((multiComp.groupsunique))
    
    # Generate a print -------------------
    
    # Get the data
    xvals = np.arange(3)
    res2 = pairwise_tukeyhsd(data['StressReduction'], data['Treatment'])
    errors = np.ravel(np.diff(res2.confint)/2)
    
    # Plot them
    plt.plot(xvals, res2.meandiffs, 'o')
    plt.errorbar(xvals, res2.meandiffs, yerr=errors, ls='o')
    
    # Put on labels
    pair_labels = multiComp.groupsunique[np.column_stack(res2._multicomp.pairindices)]
    plt.xticks(xvals, pair_labels)
    
    # Format the plot
    xlim = -0.5, 2.5
    plt.hlines(0, *xlim)
    plt.xlim(*xlim)
    plt.title('Multiple Comparison of Means - Tukey HSD, FWER=0.05' +
              '\n Pairwise Mean Differences')          
    
    # Save to outfile, and show the data
    outFile = 'multComp.png'
    C2_8_mystyle.printout_plain(outFile)
开发者ID:ejmurray,项目名称:statsintro_python,代码行数:40,代码来源:C8_3_multipleTesting.py


注:本文中的C2_8_mystyle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。