-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotter.py
37 lines (32 loc) · 1003 Bytes
/
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
#!/usr/bin/python
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
with open("result.txt", 'r') as f:
data = f.read()
data = data.split('\n')
solve = []
for row in data:
row = row.split(' ')[:-1]
row = [float(elem) for elem in row]
solve.append(row)
solve = np.array(solve)
dim = solve.shape[0]
x = np.linspace(-2.0, 2.0, solve.shape[0])
y = np.linspace(-2.0, 2.0, solve.shape[1])
xx, yy = np.meshgrid(x, y, sparse=True)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("u(x, y)")
surf = ax.plot_surface(xx, yy, solve, cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
ax.view_init(30, 30)
plt.show()
# fig.savefig('images/dim_{}.eps'.format(dim))
# plt.close(fig)