Beispiel #1
0
def plot_contour(function):
    """
    I tried to show a 2D contour plot but it does not work properly, this function can be ignored.
    It will only remain here as a proof that I tried.
    """
    #x = arange(-1.5, 1.5, 0.01)
    #y = arange(-0.5, 1.5, 0.01)
    x = arange(-100, 250, 50)
    y = arange(-100, 250, 50)
    [X, Y] = meshgrid(x, y)
    Z = function(X, Y)
    #    XY = map(zip, x, y)
    #    Z = map(function, XY)
    #    import ipdb; ipdb.set_trace() # BREAKPOINT
    plt.figure()
    im = plt.imshow(Z,
                    interpolation='bilinear',
                    origin='lower',
                    cmap=cm.gray,
                    extent=(-3, 3, -2, 2))
    levels = np.arange(-1.2, 1.6, 0.2)
    CS = plt.contour(Z,
                     levels,
                     origin='lower',
                     linewidths=2,
                     extent=(-3, 3, -2, 2))

    #Thicken the zero contour.
    zc = CS.collections[6]
    plt.setp(zc, linewidth=4)

    plt.clabel(
        CS,
        levels[1::2],  # label every second level
        inline=1,
        fmt='%1.1f',
        fontsize=14)

    # make a colorbar for the contour lines
    CB = plt.colorbar(CS, shrink=0.8, extend='both')

    plt.title('Lines with colorbar')
    #plt.hot()  # Now change the colormap for the contour lines and colorbar
    plt.flag()

    # We can still add a colorbar for the image, too.
    CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)

    # This makes the original colorbar look a bit out of place,
    # so let's improve its position.

    l, b, w, h = plt.gca().get_position().bounds
    ll, bb, ww, hh = CB.ax.get_position().bounds
    CB.ax.set_position([ll, b + 0.1 * h, ww, h * 0.8])

    plt.show()
Beispiel #2
0
def draw_digit(data):
    size = 28
    X, Y = np.meshgrid(range(size), range(size))
    Z = data.reshape(size, size)  # convert from vector to 28x28 matrix
    Z = Z[::-1, :]  # flip vertical
    plt.xlim(0, 27)
    plt.ylim(0, 27)
    plt.pcolor(X, Y, Z)
    plt.flag()
    plt.gray()
    plt.tick_params(labelbottom="off")
    plt.tick_params(labelleft="off")
def draw_digit(data):
    size = 28
    X, Y = np.meshgrid(range(size),range(size))
    Z = data.reshape(size,size)   # convert from vector to 28x28 matrix
    Z = Z[::-1,:]             # flip vertical
    plt.xlim(0,27)
    plt.ylim(0,27)
    plt.pcolor(X, Y, Z)
    plt.flag()
    plt.gray()
    plt.tick_params(labelbottom="off")
    plt.tick_params(labelleft="off")
Beispiel #4
0
def plot_contour(function):
    """
    I tried to show a 2D contour plot but it does not work properly, this function can be ignored.
    It will only remain here as a proof that I tried.
    """
    #x = arange(-1.5, 1.5, 0.01)
    #y = arange(-0.5, 1.5, 0.01)
    x = arange(-100, 250, 50)
    y = arange(-100, 250, 50)
    [X, Y] = meshgrid(x, y)
    Z = function(X, Y)
#    XY = map(zip, x, y)
#    Z = map(function, XY)
#    import ipdb; ipdb.set_trace() # BREAKPOINT
    plt.figure()
    im = plt.imshow(Z, interpolation='bilinear', origin='lower',
                    cmap=cm.gray, extent=(-3,3,-2,2))
    levels = np.arange(-1.2, 1.6, 0.2)
    CS = plt.contour(Z, levels,
                    origin='lower',
                    linewidths=2,
                    extent=(-3,3,-2,2))

    #Thicken the zero contour.
    zc = CS.collections[6]
    plt.setp(zc, linewidth=4)

    plt.clabel(CS, levels[1::2],  # label every second level
            inline=1,
            fmt='%1.1f',
            fontsize=14)

    # make a colorbar for the contour lines
    CB = plt.colorbar(CS, shrink=0.8, extend='both')

    plt.title('Lines with colorbar')
    #plt.hot()  # Now change the colormap for the contour lines and colorbar
    plt.flag()

    # We can still add a colorbar for the image, too.
    CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)

    # This makes the original colorbar look a bit out of place,
    # so let's improve its position.

    l,b,w,h = plt.gca().get_position().bounds
    ll,bb,ww,hh = CB.ax.get_position().bounds
    CB.ax.set_position([ll, b+0.1*h, ww, h*0.8])

    plt.show()
Beispiel #5
0
def plotFSRSContour(data, t, w, saveFig, autoClose):

    matplotlib.rcParams['xtick.direction'] = 'out'
    matplotlib.rcParams['ytick.direction'] = 'out'
    plt.figure()
    im = plt.imshow(data,
                    interpolation='bilinear',
                    origin='lower',
                    cmap=cm.jet,
                    extent=(t[0, 0], t[-1, -1], w[0, 0], w[-1, -1]))
    levels = np.arange(np.amin(data), np.amax(data),
                       (np.amax(data) - np.amin(data)) / 4)

    CS = plt.contour(data,
                     levels,
                     origin='lower',
                     linewidths=1,
                     extent=(t[0, 0], t[-1, -1], w[0, 0], w[-1, -1]))

    # Thicken the zero contour.
    zc = CS.collections
    plt.setp(zc, linewidth=1)

    plt.title('FSRS Time Evolution')
    plt.flag()

    # We can still add a colorbar for the image, too.
    CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)

    l, b, width, height = plt.gca().get_position().bounds

    if saveFig:
        plt.savefig('ContourFSRSEvolution0.pdf')

    if autoClose:
        plt.show(block=False)
        plt.pause(3)
        plt.close()
    else:
        plt.show()
Beispiel #6
0
#Thicken the zero contour.
zc = CS.collections[6]
plt.setp(zc, linewidth=4)

plt.clabel(
    CS,
    levels[1::2],  # label every second level
    inline=1,
    fmt='%1.1f',
    fontsize=14)

# make a colorbar for the contour lines
#CB = plt.colorbar(CS, shrink=0.8, extend='both')

plt.title('Kalman Filter')
#plt.hot()  # Now change the colormap for the contour lines and colorbar
plt.flag()

# We can still add a colorbar for the image, too.
CBI = plt.colorbar(im, orientation='vertical', shrink=0.8)

# This makes the original colorbar look a bit out of place,
# so let's improve its position.

l, b, w, h = plt.gca().get_position().bounds
#ll,bb,ww,hh = CB.ax.get_position().bounds
#CB.ax.set_position([ll, b+0.1*h, ww, h*0.8])

plt.plot(25, 25, 'ro', markersize=12)

plt.show()
Beispiel #7
0
plt.scatter([xSource,xSink],[ySource,ySink],c='#CD2305',s=80,marker='o')

#calculate the potential function

Z=np.empty_like(uSource)

#for i in range(N):
#    for j in range(N):

Z=strengthSource/(2*pi)*np.log(np.sqrt(((X-xSource)**2+(Y-ySource)**2)))\
                 +strengthSink/(2*pi)*np.log(np.sqrt(((X-xSink)**2+(Y-ySink)**2)))   

plt.contourf(X,Y,Z,500)
plt.figure()
im = plt.imshow(Z, interpolation='bilinear', origin='lower',
                cmap=cm.gray, extent=(-3,3,-2,2))
levels = np.arange(-1.2, 1.6, 0.2)
CS = plt.contourf(Z, origin='lower',
                extent=(-3,3,-2,2))
                 
#CB = plt.colorbar(CS, shrink=0.8, extend='both')

plt.title('Lines with colorbar')
#plt.hot()  # Now change the colormap for the contour lines and colorbar
plt.flag()

# We can still add a colorbar for the image, too.
CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)

plt.show()
Beispiel #8
0
def plot_shape(m_f, s_f, m_tau, s_tau, w_arr, sig_w):

    def lackoffit(m, sV0, shape, scale, x, data):
        """ model decaying sine wave, subtract data"""

        tau = RV('gamma', shape=shape, scale=scale, loc=0.)
        n_int = 500
        p_arr = np.linspace(0.5 / n_int, 1 - 0.5 / n_int, n_int)
        tau_arr = tau.ppf(p_arr) + 1e-10
        r = 3.5e-3
        E_f = 180e3
        lm = 1000.

        def cdf(e, depsf, r, lm, m, sV0):
            '''weibull_fibers_cdf_mc'''
            s = ((depsf * (m + 1.) * sV0 ** m) /
                 (2. * pi * r ** 2.)) ** (1. / (m + 1.))
            a0 = (e + 1e-15) / depsf
            expfree = (e / s) ** (m + 1.)
            expfixed = a0 / \
                (lm / 2.0) * (e / s) ** (m + 1.) * \
                (1. - (1. - lm / 2.0 / a0) ** (m + 1.))
            mask = a0 < lm / 2.0
            exp = expfree * mask + \
                np.nan_to_num(expfixed * (mask == False))
            return 1. - np.exp(- exp)

        T = 2. * tau_arr / r + 1e-10

        ef0cb = np.sqrt(x[:, np.newaxis] * T[np.newaxis, :] / E_f)
        ef0lin = x[:, np.newaxis] / lm + \
            T[np.newaxis, :] * lm / 4. / E_f
        depsf = T / E_f
        a0 = ef0cb / depsf
        mask = a0 < lm / 2.0
        e = ef0cb * mask + ef0lin * (mask == False)
        Gxi = cdf(e, depsf, r, lm, m, sV0)
        mu_int = e * (1. - Gxi)
        sigma = mu_int * E_f

        residual = np.sum(sigma, axis=1) / n_int * (11. * 0.445) / 1000 - data

        return np.sum(residual ** 2)

    n = 30
    m_f_arr = np.linspace(0.75 * m_f, 1.25 * m_f, n)
    m_tau_arr = np.linspace(0.75 * m_tau, 1.25 * m_tau, n)

    X, Y = np.meshgrid(m_f_arr, m_tau_arr)

    delta = np.zeros((n, n))

    for i in range(n):
        for j in range(n):
            print(j)
            delta[i, j] = lackoffit(
                X[i, j], s_f, Y[i, j], s_tau, w_arr, sig_w)

    # fig = plt.figure()
    # ax = fig.gca(projection='3d')
    # ax.plot_surface(X, Y, delta,  rstride=1, cstride=1, cmap=cm.Greys_r)

    # print 'x'
    # print X
    # print 'y'
    # print Y
    # print 'z'
    # print delta

    plt.figure(figsize=(12, 9))
    im = plt.imshow(delta, interpolation='bilinear', origin='lower',
                    cmap=cm.gray, extent=(0.75 * m_f, 1.25 * m_f, 0.75 * m_tau, 1.25 * m_tau), aspect=m_f / m_tau)
    levels = np.arange(0, 5, 0.2)
    CS = plt.contour(delta, levels,
                     origin='lower',
                     linewidths=2,
                     extent=(0.75 * m_f, 1.25 * m_f, 0.75 * m_tau, 1.25 * m_tau))
    plt.clabel(CS, levels[1::2],  # label every second level
               inline=1,
               fmt='%1.1f',
               fontsize=12)
    # CB = plt.colorbar(CS, shrink=0.8, extend='both')

    plt.title('lack of fit')
    # plt.hot()  # Now change the colormap for the contour lines and colorbar
    plt.flag()

    # We can still add a colorbar for the image, too.
    CBI = plt.colorbar(im, shrink=0.8)

    # This makes the original colorbar look a bit out of place,
    # so let's improve its position.

    # l, b, w, h = plt.gca().get_position().bounds
    # ll, bb, ww, hh = CB.ax.get_position().bounds
    # CB.ax.set_position([ll, b + 0.1 * h, ww, h * 0.8])
    plt.plot(m_f, m_tau, 'ro')
    plt.xlabel('m_f')
    plt.ylabel('m_tau')
    path = 'D:\\fig\\shape'
    plt.savefig(path)
	def TestContour(self): 
		import matplotlib.font_manager as fnt
		import matplotlib.cm as cm
		import matplotlib.mlab as mlab
		import matplotlib.pyplot as plt
		# Make plot styles visible. 
		PlotFont = {'fontname':'Helvetica','fontsize':18,'weight':'bold'}
		LegendFont = fnt.FontProperties(family='Helvetica',size='17',weight='bold')
		matplotlib.rcParams['xtick.direction'] = 'out'
		matplotlib.rcParams['ytick.direction'] = 'out'
		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)
		# difference of Gaussians
		Z = 10.0 * (Z2 - Z1)
		# Create a simple contour plot with labels using default colors.  The
		# inline argument to clabel will control whether the labels are draw
		# over the line segments of the contour, removing the lines beneath
		# the label
		plt.figure()
		CS = plt.contour(X, Y, Z)
		plt.clabel(CS, inline=1, fontsize=10)
		plt.title('Simplest default with labels')
		# You can force all the contours to be the same color.
		plt.figure()
		CS = plt.contour(X, Y, Z, 6,
						 colors='k', # negative contours will be dashed by default
						 )
		plt.clabel(CS, fontsize=9, inline=1)
		plt.title('Single color - negative contours dashed')
		# You can set negative contours to be solid instead of dashed:
		matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
		plt.figure()
		CS = plt.contour(X, Y, Z, 6,
						 colors='k', # negative contours will be dashed by default
						 )
		plt.clabel(CS, fontsize=9, inline=1)
		plt.title('Single color - negative contours solid')
		# And you can manually specify the colors of the contour
		plt.figure()
		CS = plt.contour(X, Y, Z, 6,
						 linewidths=numpy.arange(.5, 4, .5),
						 colors=('r', 'green', 'blue', (1,1,0), '#afeeee', '0.5')
						 )
		plt.clabel(CS, fontsize=9, inline=1)
		plt.title('Crazy lines')
		# Or you can use a colormap to specify the colors; the default
		# colormap will be used for the contour lines
		plt.figure()
		im = plt.imshow(Z, interpolation='bilinear', origin='lower',
						cmap=cm.gray, extent=(-3,3,-2,2))
		levels = numpy.arange(-1.2, 1.6, 0.2)
		CS = plt.contour(Z, levels,
						 origin='lower',
						 linewidths=2,
						 extent=(-3,3,-2,2))

		#Thicken the zero contour.
		zc = CS.collections[6]
		plt.setp(zc, linewidth=4)

		plt.clabel(CS, levels[1::2],  # label every second level
				   inline=1,
				   fmt='%1.1f',
				   fontsize=14)
		# make a colorbar for the contour lines
		CB = plt.colorbar(CS, shrink=0.8, extend='both')
		plt.title('Lines with colorbar')
		#plt.hot()  # Now change the colormap for the contour lines and colorbar
		plt.flag()
		# We can still add a colorbar for the image, too.
		CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)
		# This makes the original colorbar look a bit out of place,
		# so let's improve its position.
		l,b,w,h = plt.gca().get_position().bounds
		ll,bb,ww,hh = CB.ax.get_position().bounds
		CB.ax.set_position([ll, b+0.1*h, ww, h*0.8])
		plt.show()
		return 
Beispiel #10
0
def contours():
    # !/usr/bin/env python
    """
    Illustrate simple contour plotting, contours on an image with
    a colorbar for the contours, and labelled contours.

    See also contour_image.py.
    """
    # import matplotlib
    # import numpy as np
    # import matplotlib.cm as cm
    # import matplotlib.mlab as mlab
    # import matplotlib.pyplot as plt

    plt.rcParams['xtick.direction'] = 'out'
    plt.rcParams['ytick.direction'] = 'out'

    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)

    # Create a simple contour plot with labels using default colors.  The
    # inline argument to clabel will control whether the labels are draw
    # over the line segments of the contour, removing the lines beneath
    # the label
    plt.figure()
    CS = plt.contour(X, Y, Z)
    plt.clabel(CS, inline=1, fontsize=10)
    plt.title('Simplest default with labels')

    # contour labels can be placed manually by providing list of positions
    # (in data coordinate). See ginput_manual_clabel.py for interactive
    # placement.
    plt.figure()
    CS = plt.contour(X, Y, Z)
    manual_locations = [(-1, -1.4), (-0.62, -0.7), (-2, 0.5), (1.7, 1.2),
                        (2.0, 1.4), (2.4, 1.7)]
    plt.clabel(CS, inline=1, fontsize=10, manual=manual_locations)
    plt.title('labels at selected locations')

    # You can force all the contours to be the same color.
    plt.figure()
    CS = plt.contour(
        X,
        Y,
        Z,
        6,
        colors='k',  # negative contours will be dashed by default
    )
    plt.clabel(CS, fontsize=9, inline=1)
    plt.title('Single color - negative contours dashed')

    # You can set negative contours to be solid instead of dashed:
    plt.rcParams['contour.negative_linestyle'] = 'solid'
    plt.figure()
    CS = plt.contour(
        X,
        Y,
        Z,
        6,
        colors='k',  # negative contours will be dashed by default
    )
    plt.clabel(CS, fontsize=9, inline=1)
    plt.title('Single color - negative contours solid')

    # And you can manually specify the colors of the contour
    plt.figure()
    CS = plt.contour(X,
                     Y,
                     Z,
                     6,
                     linewidths=np.arange(.5, 4, .5),
                     colors=('r', 'green', 'blue', (1, 1, 0), '#afeeee',
                             '0.5'))
    plt.clabel(CS, fontsize=9, inline=1)
    plt.title('Crazy lines')

    # Or you can use a colormap to specify the colors; the default
    # colormap will be used for the contour lines
    plt.figure()
    im = plt.imshow(Z,
                    interpolation='bilinear',
                    origin='lower',
                    cmap=cm.gray,
                    extent=(-3, 3, -2, 2))
    levels = np.arange(-1.2, 1.6, 0.2)
    CS = plt.contour(Z,
                     levels,
                     origin='lower',
                     linewidths=2,
                     extent=(-3, 3, -2, 2))

    # Thicken the zero contour.
    zc = CS.collections[6]
    plt.setp(zc, linewidth=4)

    plt.clabel(
        CS,
        levels[1::2],  # label every second level
        inline=1,
        fmt='%1.1f',
        fontsize=14)

    # make a colorbar for the contour lines
    CB = plt.colorbar(CS, shrink=0.8, extend='both')

    plt.title('Lines with colorbar')
    # plt.hot()  # Now change the colormap for the contour lines and colorbar
    plt.flag()

    # We can still add a colorbar for the image, too.
    CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)

    # This makes the original colorbar look a bit out of place,
    # so let's improve its position.

    l, b, w, h = plt.gca().get_position().bounds
    ll, bb, ww, hh = CB.ax.get_position().bounds
    CB.ax.set_position([ll, b + 0.1 * h, ww, h * 0.8])

    plt.show()
Beispiel #11
0
    def graph1(self):
        user_id = session.get('user_id')
        if not user_id:
            raise Exception


        matplotlib.rcParams['xtick.direction'] = 'out'
        matplotlib.rcParams['ytick.direction'] = 'out'
        
        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)
        
        
        
        # Create a simple contour plot with labels using default colors.  The
        # inline argument to clabel will control whether the labels are draw
        # over the line segments of the contour, removing the lines beneath
        # the label
        plt.figure()
        CS = plt.contour(X, Y, Z)
        plt.clabel(CS, inline=1, fontsize=10)
        plt.title('Simplest default with labels')
        
        plt.savefig('/Users/smitamore/cyberweb/cyberweb/public/images/contour1.png')
        
        # You can force all the contours to be the same color.
        plt.figure()
        CS = plt.contour(X, Y, Z, 6,
                         colors='k', # negative contours will be dashed by default
                         )
        plt.clabel(CS, fontsize=9, inline=1)
        plt.title('Single color - negative contours dashed')
        
        
        # You can set negative contours to be solid instead of dashed:
        matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
        plt.figure()
        CS = plt.contour(X, Y, Z, 6,
                         colors='k', # negative contours will be dashed by default
                         )
        plt.clabel(CS, fontsize=9, inline=1)
        plt.title('Single color - negative contours solid')
        
        plt.savefig('/Users/smitamore/cyberweb/cyberweb/public/images/contour2.png')
        
        # And you can manually specify the colors of the contour
        plt.figure()
        CS = plt.contour(X, Y, Z, 6,
                         linewidths=np.arange(.5, 4, .5),
                         colors=('r', 'green', 'blue', (1,1,0), '#afeeee', '0.5')
                         )
        plt.clabel(CS, fontsize=9, inline=1)
        plt.title('Crazy lines')
        
        plt.savefig('/Users/smitamore/cyberweb/cyberweb/public/images/contour3.png')
        
        # Or you can use a colormap to specify the colors; the default
        # colormap will be used for the contour lines
        plt.figure()
        im = plt.imshow(Z, interpolation='bilinear', origin='lower',
                        cmap=cm.gray, extent=(-3,3,-2,2))
        levels = np.arange(-1.2, 1.6, 0.2)
        CS = plt.contour(Z, levels,
                         origin='lower',
                         linewidths=2,
                         extent=(-3,3,-2,2))
        
        #Thicken the zero contour.
        zc = CS.collections[6]
        plt.setp(zc, linewidth=4)
        
        plt.clabel(CS, levels[1::2],  # label every second level
                   inline=1,
                   fmt='%1.1f',
                   fontsize=14)
        
        # make a colorbar for the contour lines
        CB = plt.colorbar(CS, shrink=0.8, extend='both')
        
        plt.title('Lines with colorbar')
        #plt.hot()  # Now change the colormap for the contour lines and colorbar
        plt.flag()
        
        # We can still add a colorbar for the image, too.
        CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8)
        
        # This makes the original colorbar look a bit out of place,
        # so let's improve its position.
        
        l,b,w,h = plt.gca().get_position().bounds
        ll,bb,ww,hh = CB.ax.get_position().bounds
        CB.ax.set_position([ll, b+0.1*h, ww, h*0.8])
        
        
        #plt.show()
        plt.savefig('/Users/smitamore/cyberweb/cyberweb/public/images/contour4.png')

        # Messages
        num_messages = 10
        messages = meta.Session.query(Message).filter(sa.or_(Message.recipient_group_id.in_(session['user_groups']),\
                                                             Message.recipient_user_id == session['user_id'],\
                                                             sa.and_(Message.recipient_group_id == sa.null(), Message.recipient_user_id == sa.null())))\
                                                             .order_by().limit(num_messages)
        c.messageheaders = ['Date','Message']
        c.messages = [ {'Date':i.date.strftime("%B %d,%Y"), 'Message':i.message} for i in messages ]


        # User Info
        user = meta.Session.query(User).filter(User.id == session.get('user_id')).one()
        c.info = dict()
        c.info['Last login'] = user.last_login_date
        c.info['from'] = user.last_login_ip
        c.myproxy_cmd=""
        meta.Session.close()
       
        return render('/graphs/graph1.mako')