-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadfile.py
57 lines (44 loc) · 1.23 KB
/
readfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import netCDF4
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import netCDF4 as NC
#get data
dat = NC.Dataset('output_data', 'r', format='NETCDF4')
#extract variables
ex = dat.variables['Ex'][:,:]
xpos = dat.variables['x'][:]
ypos = dat.variables['y'][:]
xax = dat.variables['x_axis'][:]
yax = dat.variables['y_axis'][:]
# set [-1. 1] axes for the plots and make them look neat
xaxis = xax[0::10]
xaxis[-1] = round(xaxis[-1], 1)
xaxis[0] = round(xaxis[0], 1)
yaxis = yax[0::10]
yaxis[-1] = round(yaxis[-1], 1)
yaxis[0] = round(yaxis[0], 1)
xnum = np.linspace(0, len(xax), len(xaxis))
ynum = np.linspace(0, len(yax), len(yaxis))
#a pseudocolour plot
plt.plot()
plt.xlabel('x position')
plt.ylabel('y position')
plt.imshow(ex, interpolation='none')
plt.title('Electric field Ex')
plt.colorbar(cmap='jet', label ='Electric field')
plt.xticks(xnum, xaxis)
plt.yticks(ynum, yaxis)
plt.show()
#a scatter plot
plt.plot()
plt.scatter(xpos, ypos)
plt.xlabel("x position")
plt.ylabel("y position")
plt.title("Particle position")
#the plot is zoomed in to illustrate the movement of the particles more clearly
#uncomment to zoom the plot out to the [-1, 1] domain:
#plt.xticks(xaxis)
#plt.yticks(yaxis)
plt.show()