-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotter.py
121 lines (81 loc) · 3.12 KB
/
plotter.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from subprocess import Popen
import os
debugDll = os.getcwd() + "\\x64\\Debug\\TuringPatterns.exe"
releaseDll = os.getcwd() + "\\x64\\Release\\TuringPatterns.exe"
def __ax_formatter(ax, title="", x_label="", y_label="", show_legend=False):
ax.set_title(title)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
if show_legend:
ax.legend(loc='best')
def surf(z, x, y, title="", x_label="", y_label="", show_legend=False, show=False):
fig = plt.figure()
ax = fig.gca(projection='3d')
# Create X and Y data
x_grid, y_grid = np.meshgrid(x, y)
ax.plot_surface(x_grid, y_grid, z, cmap=cm.coolwarm, rstride=16, cstride=16, antialiased=True)
__ax_formatter(ax, title, x_label, y_label, show_legend)
if show:
plt.show()
def plot(z, x, title="", x_label="", y_label="", show_legend=False, show=False):
fig = plt.figure()
ax = fig.add_subplot(111)
for i in range(len(x)):
ax.plot(z[:, i])
__ax_formatter(ax, title, x_label, y_label, show_legend)
if show:
plt.show()
def animate(z, x, show=False, save=False, name=""):
fig, ax = plt.subplots()
line, = ax.plot(x, z[:, 0])
def update_line(i):
if i >= z.shape[1]:
return line,
line.set_ydata(z[:, i]) # update the data
return line,
# Init only required for blitting to give a clean slate.
def init():
line.set_ydata(z[:, 0])
return line,
ani = animation.FuncAnimation(fig, update_line, np.arange(1, 200), init_func=init, interval=25, blit=True)
if show:
plt.show()
if save:
ani.save(name, writer='imagemagick', fps=60)
def animate_3D(z, x, y, rstride=1, cstride=1, cmap=cm.coolwarm, show=False, save=False, name=""):
fig = plt.figure()
ax = fig.gca(projection='3d')
# Create X and Y data
x_grid, y_grid = np.meshgrid(x, y)
line = ax.plot_surface(x_grid, y_grid, z[0], cmap=cmap, rstride=rstride, cstride=cstride, antialiased=True)
def update_line(i):
if i >= z.shape[0]:
return line,
ax.clear()
l = ax.plot_surface(x_grid, y_grid, z[i], cmap=cm.coolwarm,rstride=rstride, cstride=cstride, antialiased=True)
return l,
ani = animation.FuncAnimation(fig, update_line, np.arange(1, 200), interval=25, blit=False)
if show:
plt.show()
if save:
ani.save(name, writer='imagemagick', fps=60)
def animate_colormap(z, x, y, cmap='PuBu_r', shading='gouraud', show=False, save=False, name=""):
fig, ax = plt.subplots()
x, y = np.meshgrid(x, y)
ax.pcolormesh(x, y, z[0], shading=shading, cmap=cmap)
def update_line(i):
if i >= z.shape[0]:
return None,
ax.clear()
ax.pcolormesh(x, y, z[i], shading=shading, cmap=cmap)
return None,
ani = animation.FuncAnimation(fig, update_line, np.arange(1, 200), interval=25, blit=False)
if show:
plt.show()
if save:
ani.save(name, writer='imagemagick', fps=60)