Python matplotlib.mlab.bivariate_normal() Examples

The following are 11 code examples of matplotlib.mlab.bivariate_normal(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.mlab , or try the search function .
Example #1
Source File: test_plotting.py    From cesiumpy with Apache License 2.0 7 votes vote down vote up
def test_contour_xyz(self):
        _skip_if_no_matplotlib()
        import numpy as np
        import matplotlib.mlab as mlab

        delta = 0.025
        x = np.arange(-3.0, 3.0, delta)
        y = np.arange(-2.0, 2.0, delta)
        X, Y = np.meshgrid(x, y)
        Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
        Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
        # difference of Gaussians
        Z = 10.0 * (Z2 - Z1)

        viewer = cesiumpy.Viewer()
        viewer.plot.contour(X, Y, Z)
        self.assertEqual(len(viewer.entities), 7)
        self.assertTrue(all(isinstance(x, cesiumpy.Polyline)
                            for x in viewer.entities))
        self.assertEqual(viewer.entities[0].material,
                         cesiumpy.color.Color(0.0, 0.0, 0.5, 1.0)) 
Example #2
Source File: axes3d.py    From Computable with MIT License 6 votes vote down vote up
def get_test_data(delta=0.05):
    '''
    Return a tuple X, Y, Z with a test data set.
    '''

    from matplotlib.mlab import  bivariate_normal
    x = y = np.arange(-3.0, 3.0, delta)
    X, Y = np.meshgrid(x, y)

    Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
    Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
    Z = Z2 - Z1

    X = X * 10
    Y = Y * 10
    Z = Z * 500
    return X, Y, Z



########################################################
# Register Axes3D as a 'projection' object available
# for use just like any other axes
######################################################## 
Example #3
Source File: axes3d.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def get_test_data(delta=0.05):
    '''
    Return a tuple X, Y, Z with a test data set.
    '''

    from matplotlib.mlab import  bivariate_normal
    x = y = np.arange(-3.0, 3.0, delta)
    X, Y = np.meshgrid(x, y)

    Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
    Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
    Z = Z2 - Z1

    X = X * 10
    Y = Y * 10
    Z = Z * 500
    return X, Y, Z



########################################################
# Register Axes3D as a 'projection' object available
# for use just like any other axes
######################################################## 
Example #4
Source File: test_contour.py    From neural-network-animation with MIT License 6 votes vote down vote up
def test_labels():
    # Adapted from pylab_examples example code: contour_demo.py
    # see issues #2475, #2843, and #2818 for explanation
    delta = 0.025
    x = np.arange(-3.0, 3.0, delta)
    y = np.arange(-2.0, 2.0, delta)
    X, Y = np.meshgrid(x, y)
    Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
    Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
    # difference of Gaussians
    Z = 10.0 * (Z2 - Z1)

    fig, ax = plt.subplots(1, 1)
    CS = ax.contour(X, Y, Z)
    disp_units = [(216, 177), (359, 290), (521, 406)]
    data_units = [(-2, .5), (0, -1.5), (2.8, 1)]

    CS.clabel()

    for x, y in data_units:
        CS.add_label_near(x, y, inline=True, transform=None)

    for x, y in disp_units:
        CS.add_label_near(x, y, inline=True, transform=False) 
Example #5
Source File: axes3d.py    From opticspy with MIT License 6 votes vote down vote up
def get_test_data(delta=0.05):
    '''
    Return a tuple X, Y, Z with a test data set.
    '''

    from matplotlib.mlab import  bivariate_normal
    x = y = np.arange(-3.0, 3.0, delta)
    X, Y = np.meshgrid(x, y)

    Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
    Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
    Z = Z2 - Z1

    X = X * 10
    Y = Y * 10
    Z = Z * 500
    return X, Y, Z



########################################################
# Register Axes3D as a 'projection' object available
# for use just like any other axes
######################################################## 
Example #6
Source File: eval_hand.py    From DL-Seq2Seq with MIT License 6 votes vote down vote up
def gauss_params_plot(strokes, title ='Distribution of Gaussian Mixture parameters', figsize = (20,2)):
    plt.figure(figsize=figsize)
    import matplotlib.mlab as mlab
    buff = 1 ; epsilon = 1e-4
    minx, maxx = np.min(strokes[:,0])-buff, np.max(strokes[:,0])+buff
    miny, maxy = np.min(strokes[:,1])-buff, np.max(strokes[:,1])+buff
    delta = abs(maxx-minx)/400. ;
    
    x = np.arange(minx, maxx, delta)
    y = np.arange(miny, maxy, delta)
    X, Y = np.meshgrid(x, y)
    Z = np.zeros_like(X)
    for i in range(strokes.shape[0]):
        gauss = mlab.bivariate_normal(X, Y, mux=strokes[i,0], muy=strokes[i,1], \
            sigmax=strokes[i,2], sigmay=strokes[i,3], sigmaxy=0) # sigmaxy=strokes[i,4] gives error
        Z += gauss * np.power(strokes[i,3] + strokes[i,2], .4) / (np.max(gauss) + epsilon)
    
    plt.title(title, fontsize=20)
    plt.imshow(np.flipud(Z), cmap=cm.gnuplot) 
Example #7
Source File: __init__.py    From 3DGCN with MIT License 5 votes vote down vote up
def calcAtomGaussians(mol, a=0.03, step=0.02, weights=None):
    """
  useful things to do with these:
  fig.axes[0].imshow(z,cmap=cm.gray,interpolation='bilinear',origin='lower',extent=(0,1,0,1))
  fig.axes[0].contour(x,y,z,20,colors='k')

  fig=Draw.MolToMPL(m);
  contribs=Crippen.rdMolDescriptors._CalcCrippenContribs(m)
  logps,mrs=zip(*contribs)
  x,y,z=Draw.calcAtomGaussians(m,0.03,step=0.01,weights=logps)
  fig.axes[0].imshow(z,cmap=cm.jet,interpolation='bilinear',origin='lower',extent=(0,1,0,1))
  fig.axes[0].contour(x,y,z,20,colors='k',alpha=0.5)
  fig.savefig('coumlogps.colored.png',bbox_inches='tight')


    """
    import numpy
    from matplotlib import mlab
    x = numpy.arange(0, 1, step)
    y = numpy.arange(0, 1, step)
    X, Y = numpy.meshgrid(x, y)
    if weights is None:
        weights = [1.] * mol.GetNumAtoms()
    Z = mlab.bivariate_normal(X, Y, a, a, mol._atomPs[0][0], mol._atomPs[0][1]) * weights[0]
    for i in range(1, mol.GetNumAtoms()):
        Zp = mlab.bivariate_normal(X, Y, a, a, mol._atomPs[i][0], mol._atomPs[i][1])
        Z += Zp * weights[i]
    return X, Y, Z 
Example #8
Source File: artist-demo.py    From matplotlib-style-gallery with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def image_demo(fig, ax):
    delta = 0.025
    x = y = np.arange(-3.0, 3.0, delta)
    xx, yy = np.meshgrid(x, y)
    z1 = mlab.bivariate_normal(xx, yy, 1.0, 1.0, 0.0, 0.0)
    z2 = mlab.bivariate_normal(xx, yy, 1.5, 0.5, 1, 1)
    image = z2-z1  # Difference of Gaussians
    img_plot = ax.imshow(image)
    ax.set_title('image')

    fig.tight_layout()
    # `colorbar` should be called after `tight_layout`.
    fig.colorbar(img_plot, ax=ax) 
Example #9
Source File: gaussian_contours.py    From QuantEcon.lectures.code with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def gen_gaussian_plot_vals(μ, C):
    "Z values for plotting the bivariate Gaussian N(μ, C)"
    m_x, m_y = float(μ[0]), float(μ[1])
    s_x, s_y = np.sqrt(C[0, 0]), np.sqrt(C[1, 1])
    s_xy = C[0, 1]
    return bivariate_normal(X, Y, s_x, s_y, m_x, m_y, s_xy) 
Example #10
Source File: test_matplotlib.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def main():
    # Part of the example at 
    # http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/contour_demo.py
    delta = 0.025
    x = numpy.arange(-3.0, 3.0, delta)
    y = numpy.arange(-2.0, 2.0, delta)
    X, Y = numpy.meshgrid(x, y)
    Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
    Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
    Z = 10.0 * (Z2 - Z1)
    pyplot.figure()
    CS = pyplot.contour(X, Y, Z)
    pyplot.show() 
Example #11
Source File: 3_em-for-gmm.py    From Coursera-UW-Machine-Learning-Clustering-Retrieval with MIT License 5 votes vote down vote up
def plot_contours(data, means, covs, title):
    plt.figure()
    plt.plot([x[0] for x in data], [y[1] for y in data],'ko') # data

    delta = 0.025
    k = len(means)
    x = np.arange(-2.0, 7.0, delta)
    y = np.arange(-2.0, 7.0, delta)
    X, Y = np.meshgrid(x, y)
    col = ['green', 'red', 'indigo']
    for i in range(k):
        mean = means[i]
        cov = covs[i]
        sigmax = np.sqrt(cov[0][0])
        sigmay = np.sqrt(cov[1][1])
        sigmaxy = cov[0][1]/(sigmax*sigmay)
        Z = mlab.bivariate_normal(X, Y, sigmax, sigmay, mean[0], mean[1], sigmaxy)
        plt.contour(X, Y, Z, colors = col[i])
        plt.title(title)
    plt.rcParams.update({'font.size':16})
    plt.tight_layout()


# In[26]:

# Parameters after initialization