Jump to content

Rep:Mod:DMS3053-6

From ChemWiki

CMP Programming Experiment - Daniel Spencer, 00736964
Python ILplotdata.py script - The effect of system size

   from matplotlib import pylab as pl
   import numpy as np
   def extract_data(file):
       data_array = np.loadtxt(file) # Loads file data
       list = file.split("x") # Splits the file name to find the lattice size
       spin = int(list[0])
       spins = spin*spin # Assumes a square lattice
       temps = data_array[:,0] # Creates an array of the temperature data
       energies = data_array[:,1]/spins # Creates an array of the energy data
       magnetisations = data_array[:,3]/spins # Creates an array of the magnetisation data
       return temps, energies, magnetisations
   
   def plotdata(file1, file2, file3, file4, file5):
       file1_data = extract_data(file1)
       file2_data = extract_data(file2)
       file3_data = extract_data(file3)
       file4_data = extract_data(file4)
       file5_data = extract_data(file5)
       fig = pl.figure()
       enerax = fig.add_subplot(2,1,1)
       enerax.set_ylabel("Energy per spin")
       enerax.set_xlabel("Temperature")
       enerax.set_ylim([-2.1, 0.1])
       magax = fig.add_subplot(2,1,2)
       magax.set_ylabel("Magnetisation per spin")
       magax.set_xlabel("Temperature")
       magax.set_ylim([-1.1, 1.1])
       enerax.plot(file1_data[0], file1_data[1], file2_data[0], 
           file2_data[1], file3_data[0], file3_data[1],
           file4_data[0], file4_data[1], file5_data[0], file5_data[1])
       enerax.legend(['2x2', '4x4', '8x8', '16x16', '32x32'], loc='upper center', bbox_to_anchor=(0.5, 1.05),
             ncol=5)
       magax.plot(file1_data[0], file1_data[2], file2_data[0], 
           file2_data[2], file3_data[0], file3_data[2],
           file4_data[0], file4_data[2], file5_data[0], file5_data[2])
       magax.legend(['2x2', '4x4', '8x8', '16x16', '32x32'], loc='upper center', bbox_to_anchor=(0.5, -0.05),
             ncol=5)
       pl.show()