cs205-lecture-examples

Example codes used during Harvard CS205 lectures
git clone https://git.0xfab.ch/cs205-lecture-examples.git
Log | Files | Refs | README | LICENSE

plot.py (532B)


      1 # File       : plot.py
      2 # Description: Plot temporal evolution of diffusing quantity
      3 # Copyright 2022 Harvard University. All Rights Reserved.
      4 import numpy as np
      5 import matplotlib.pyplot as plt
      6 
      7 def main():
      8     data = np.loadtxt('u.dat')
      9     N = data.shape[1]
     10     dx = 1.0 / N
     11     for step in range(data.shape[0]):
     12         x = (np.arange(N) + 0.5) * dx
     13         plt.plot(x, data[step, :])
     14     plt.xlabel(r'$x$')
     15     plt.ylabel(r'$u(x,t)$')
     16     plt.savefig('u.png', dpi=300, bbox_inches='tight')
     17 
     18 if __name__ == "__main__":
     19     main()