-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualization.py
103 lines (65 loc) · 2.54 KB
/
Visualization.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
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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
from matplotlib import pyplot as plt
import numpy as np
# In[2]:
class Visual():
def __init__():
pass
def visualize_vector_plot(X, Y, u_next, v_next, streamplot):
#------------------------------------------------#
plt.figure(1)
plt.xlim((0, 1))
plt.ylim((0, 0.5))
#------------------------------------------------#
if streamplot == True:
z1 = plt.streamplot(X[::2, ::2], Y[::2, ::2], u_next[::2, ::2], v_next[::2, ::2], color="black")
else:
z1 = plt.quiver(X[::2, ::2], Y[::2, ::2], u_next[::2, ::2], v_next[::2, ::2], color="black")
#plt.show()
return z1
def visualize_contour_plot(X, Y, u_next):
#------------------------------------------------#
#plt.figure()
plt.xlim((0, 1))
plt.ylim((0, 0.5))
#------------------------------------------------#
plt.contourf(X[::2, ::2], Y[::2, ::2], u_next[::2, ::2], cmap="viridis")
plt.colorbar()
#------------------------------------------------#
return None
def visualize_Spin_up_plot(Spin_up,N_ITERATIONS, xlim_pos, xlim_neg, ylim_pos, ylim_neg):
Spin_up = np.array(Spin_up)
np.shape(Spin_up)
#plt.ylabel('Error')
#plt.xlabel('Timesteps')
plt.plot(np.linspace(0,N_ITERATIONS,N_ITERATIONS),Spin_up)
plt.xlim(xlim_neg, xlim_pos)
plt.ylim(ylim_neg, ylim_pos)
plt.ylabel('Spin_up w.r.t time')
plt.xlabel('iterations')
plt.show()
return None
def animation(solution, TIME_STEP_LENGTH, X, Y):
import matplotlib.animation as animation
get_ipython().run_line_magic('matplotlib', 'notebook')
fig = plt.figure(figsize=(6.1,5),facecolor='w')
images=[]
lev=np.linspace(-1,1,50)
i=0
t=0
for sol in solution:
if i%50==0: # plots contour each 50 time steps
im=plt.contourf(X,Y,solution[i,:,:], levels=lev,vmax=1.0,vmin=-1.0)
images.append(im.collections)
i+=1
t += TIME_STEP_LENGTH
cbar = plt.colorbar()
plt.title('Contour')
#plt.clim(-1,1)
cbar.set_ticks(np.linspace(-1,1,50))
ani = animation.ArtistAnimation (fig, images, interval=35, blit= True, repeat_delay=50)
plt.show()
return None
# In[ ]: