Пример #1
0
    def _redraw(self, db, tofile=0, eta=None):
        """ redraw the updated grid interactively """
        import pylab as p

        if len(db) <= 3 or not self.plotflag:
            return
        begin_level = round(max(map(lambda (x): x[2], db))) - 3
        step_size = 0.25
        nContours = 25
        suffix = ""
        if eta is not None:
            suffix = " (ETA: %5.2f min)" % eta

        def cmp(x, y):
            if x[0] < y[0]:
                return -1
            if x[0] > y[0]:
                return 1
            if x[1] > y[1]:
                return -1
            if x[1] < y[1]:
                return 1
            return 0

        db.sort(cmp)
        dbarr = p.asarray(db)
        # reconstruct grid: array is ordered along first and second dimension
        x = dbarr[:, 0]
        dimy = len(x[x == x[0]])
        dimx = x.size / dimy
        print "plotting: ", dimx, dimy
        x = x.reshape(dimx, dimy)
        y = dbarr[:, 1]
        y = y.reshape(dimx, dimy)
        z = dbarr[:, 2].reshape(dimx, dimy)

        # plot using manual double buffer
        p.ioff()
        p.clf()
        p.contourf(x, y, z, nContours)
        p.hsv()
        p.colorbar()
        p.xlim(self.usermin[0], self.usermax[0])
        p.ylim(self.usermin[1], self.usermax[1])
        p.xlabel(r"$\rm{log}_2(C)$")
        p.ylabel(r"$\rm{log}_2(\gamma)$")
        p.ion()
        p.draw_if_interactive()
Пример #2
0
    def _redraw(self, db, tofile=0, eta=None):
        """ redraw the updated grid interactively """
        import pylab as p
        if len(db) <= 3 or not self.plotflag: return
        begin_level = round(max(map(lambda (x): x[2], db))) - 3
        step_size = 0.25
        nContours = 25
        suffix = ''
        if eta is not None:
            suffix = " (ETA: %5.2f min)" % eta

        def cmp(x, y):
            if x[0] < y[0]: return -1
            if x[0] > y[0]: return 1
            if x[1] > y[1]: return -1
            if x[1] < y[1]: return 1
            return 0

        db.sort(cmp)
        dbarr = p.asarray(db)
        # reconstruct grid: array is ordered along first and second dimension
        x = dbarr[:, 0]
        dimy = len(x[x == x[0]])
        dimx = x.size / dimy
        print 'plotting: ', dimx, dimy
        x = x.reshape(dimx, dimy)
        y = dbarr[:, 1]
        y = y.reshape(dimx, dimy)
        z = dbarr[:, 2].reshape(dimx, dimy)

        # plot using manual double buffer
        p.ioff()
        p.clf()
        p.contourf(x, y, z, nContours)
        p.hsv()
        p.colorbar()
        p.xlim(self.usermin[0], self.usermax[0])
        p.ylim(self.usermin[1], self.usermax[1])
        p.xlabel(r'$\rm{log}_2(C)$')
        p.ylabel(r'$\rm{log}_2(\gamma)$')
        p.ion()
        p.draw_if_interactive()
Пример #3
0
        magfield = zeros((11, 11))

        for i in range(0, 11):
            for k in range(0, 11):
                magfield[i, k] = sqrt(pdiff_x[i, k]**2 + pdiff_y[i, k]**2)

        clf()
        imshow(magfield, origin='lower')
        jet()
        colorbar()
        show()

    if plot in ['direction']:
        clf()
        imshow(field, origin='lower')
        hsv()
        colorbar()
        show()

if part in ['c']:

    L = 10  # cm
    field = zeros((11, 11))

    for i in range(0, 11):
        for k in range(0, 11):
            field[i, k] = chargedensity(i, k)

    clf()
    imshow(field, origin='lower')
    jet()
Пример #4
0
	pl.xlabel('Temperature') #label x axis
	pl.ylabel('Magnitude') #label y axis
	pl.xlim(16000,0) #reverse the range, to make the 
	pl.ylim(20,-5)   #reverse the range
	pl.show()
	
elif choice==3:
	#upload the circular.txt file saved in my /Users/ying.tang/GitHub/Exercises/Data dicectory
	Density = np.loadtxt("/Users/ying.tang/GitHub/Exercises/Data/circular.txt", float)
	
	#check the shape and the dimension of the data
	print "density shape %s" %(' '.join(map(str, Density.shape))) 
	#because "Density.shape" is a list, so I use function map to map all elements of the list to string type, and join them with a space in between. 
	
	pl.imshow(Density, origin="lower")  #move origin of the plot [0,0] to the lower corner
	pl.hsv() #change the color to rainbow scheme
	#pl.gray()  #change the color to black and white 
	#pl.hot()   #change the color scheme to black-yellow-red-white
	#pl.bone()   # for mimicking the color of the bone: black and white, with a hint of blue
	
	pl.colorbar()  #plot the color bar as well
	
	pl.xlabel('x')
	pl.ylabel('y')
	pl.title('Density Plot')
	
	#the default color scheme is heat-map
	pl.show()
	
else:
	print "You input a wrong number. Bye bye."
Пример #5
0
import numpy as np
import pylab as plt
""" Image with electrical potential of two charges """

df = np.loadtxt('Exemplo_imshow.txt', float)
plt.imshow(df, origin="lower")
plt.hsv()
plt.show()
Пример #6
0
    pl.ylim(20, -5)  #reverse the range
    pl.show()

elif choice == 3:
    #upload the circular.txt file saved in my /Users/ying.tang/GitHub/Exercises/Data dicectory
    Density = np.loadtxt("/Users/ying.tang/GitHub/Exercises/Data/circular.txt",
                         float)

    #check the shape and the dimension of the data
    print "density shape %s" % (' '.join(map(str, Density.shape)))
    #because "Density.shape" is a list, so I use function map to map all elements of the list to string type, and join them with a space in between.

    pl.imshow(
        Density,
        origin="lower")  #move origin of the plot [0,0] to the lower corner
    pl.hsv()  #change the color to rainbow scheme
    #pl.gray()  #change the color to black and white
    #pl.hot()   #change the color scheme to black-yellow-red-white
    #pl.bone()   # for mimicking the color of the bone: black and white, with a hint of blue

    pl.colorbar()  #plot the color bar as well

    pl.xlabel('x')
    pl.ylabel('y')
    pl.title('Density Plot')

    #the default color scheme is heat-map
    pl.show()

else:
    print "You input a wrong number. Bye bye."