-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotter.py
More file actions
131 lines (98 loc) · 3.81 KB
/
plotter.py
File metadata and controls
131 lines (98 loc) · 3.81 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import matplotlib.pyplot as plt
from numpy import arange, concatenate, linspace, log10, zeros
from scipy.interpolate import griddata
class Plotter1D:
def __init__(self, S, P):
self.S = S
self.P = P
self.f, self.ax = plt.subplots(4, figsize=(7,10), \
sharex=True, sharey=False)
self.line = [1,2,3,4]
plt.ion()
self.line[0], = self.ax[0].plot([], [], 'bo', markeredgecolor='b')
self.ax[0].set_xlim(0.0, 1.0)
self.ax[0].set_ylabel(r'$P$', fontsize = 16)
self.ax[0].set_ylim(0.0, 1.1)
self.line[1], = self.ax[1].plot([], [], 'ro', markeredgecolor='r')
self.ax[1].set_ylabel(r'$\rho$', fontsize = 16)
self.ax[1].set_ylim(0.0, 1.1)
self.line[2], = self.ax[2].plot([], [], 'go', markeredgecolor='g')
self.ax[2].set_ylabel(r'$u$', fontsize = 16)
self.ax[2].set_ylim(1.5, 3.0)
self.line[3], = self.ax[3].plot([], [], 'yo', markeredgecolor='y')
self.ax[3].set_xlabel(r'$r$', fontsize = 16)
self.ax[3].set_ylabel(r'$v$', fontsize = 16)
self.ax[3].set_ylim(0.0,1.1)
self.f.subplots_adjust(hspace=0.2)
bbprops = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
self.text = self.ax[0].text(0.75, 1.25, "", \
transform=self.ax[0].transAxes, fontsize=12, style='normal', \
bbox=bbprops)
def dataAsArrays(self):
r = zeros(self.S.np)
P = zeros(self.S.np)
rho = zeros(self.S.np)
u = zeros(self.S.np)
v = zeros(self.S.np)
for i in range(self.S.np):
r[i] = self.P[i].r[0]
P[i] = self.P[i].P
rho[i] = self.P[i].rho
u[i] = self.P[i].u
v[i] = self.P[i].v[0]
return r, P, rho, u, v
def plot(self):
r, P, rho, u, v = self.dataAsArrays()
self.line[0].set_data(r, P)
self.line[1].set_data(r, rho)
self.line[2].set_data(r, u)
self.line[3].set_data(r, v)
textstr = "$t = %6.4f$\n$dt = %7.2e$"%(self.S.time,self.S.dt)
self.text.set_text(textstr)
plt.show()
plt.draw()
class Plotter2D:
def __init__(self,S,P):
self.S = S
self.P = P
self.f, self.ax = plt.subplots(nrows=1, ncols=1, figsize=(9,7), \
sharex=False, sharey=False)
plt.ion()
self.ax.set_xlabel(r'$x$', fontsize = 16)
self.ax.set_ylabel(r'$y$', fontsize = 16)
self.ax.set_xlim(0.0,1.0)
self.ax.set_ylim(0.0,1.0)
bbprops = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
self.text = self.ax.text(0.75, 1.05, "", \
transform=self.ax.transAxes, fontsize=12, style='normal', \
bbox=bbprops)
def dataAsArrays(self):
x = zeros(self.S.np)
y = zeros(self.S.np)
r = zeros(self.S.np)
rho = zeros(self.S.np)
P = zeros(self.S.np)
for i in range(self.S.np):
x[i] = self.P[i].r[0]
y[i] = self.P[i].r[1]
rho[i] = self.P[i].rho
P[i] = self.P[i].P
r = ((x-0.5)**2+(y-0.5)**2)**(1./2)
return x, y, log10(P)
def init(self):
x, y, P = self.dataAsArrays()
self.scat = self.ax.scatter(x, y, c=P, s=50, edgecolors='none', \
vmin = -6, vmax=1)
plt.colorbar(self.scat)
textstr = "$t = %6.4f$\n$dt = %7.2e$"%(self.S.time,self.S.dt)
self.text.set_text(textstr)
plt.show()
plt.draw()
def plot(self):
x, y, P= self.dataAsArrays()
self.scat.set_offsets(concatenate((x.reshape(x.size,1), \
y.reshape(y.size,1)),axis=1))
self.scat.set_array(P)
textstr = "$t = %6.4f$\n$dt = %7.2e$"%(self.S.time,self.S.dt)
self.text.set_text(textstr)
plt.draw()