""" /lectureNote/chapters/chapt04/codes/plot_flash_1d.py An example Python 1d plotting code using a FLASH 2d data -- The Shu-Osher hydrodynamics shock tube problem on a uniform grid of size 200 x 8 See more examples and options at: http://matplotlib.org/gallery.html http://matplotlib.org/users/image_tutorial.html """ import h5py import numpy as np import os import sys import matplotlib.pyplot as plt def plot_flash_1d(file,yslice=0,var='dens',color='black') : var4plot = file[var] print(var4plot.shape) #plt.xlim(-4.5,4.5) dx = 9./200. x = np.linspace(-4.5 + 0.5*dx, 4.5, 200) plt.plot(x, var4plot[0,0,yslice,:],color=color,linewidth=2) # plot a 1D section from a 2D data # read in a data dFile = h5py.File('ppm-hllc_hdf5_chk_0009', 'r') print(dFile.keys()) # plot 1D graph plot_flash_1d(dFile,yslice=4,var='dens',color='blue') plot_flash_1d(dFile,yslice=4,var='pres',color='green') # Enable gridlines plt.grid(True) # Set x label plt.xlabel('$x$') # Set y label plt.ylabel(r'$\rho$, $p$') # legend plt.legend((r'density, $\rho$', r'pressure, $p$'), loc='center left') # show to screen plt.show() # close the file dFile.close()