from mpl_toolkits mplot3d import Axes3D from matplotlib import cm from

 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
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
from array import *
x = np.array([0, 0, 0, 400, 400, 400, 800, 800, 800])
y = np.array([0, 400, 800, 0, 400, 800, 0, 400, 800])
z = np.array([10.0, 10.0, 10.0, 10.0, 206.8, 10.0, 10.0, 10.0, 10.0])
#print len(x), len(y), len(z)
zdict = {}
for i in range (0, len(x)):
#print "(", x[i], ", ", y[i], "): ", z[i], ", "
zdict[(x[i], y[i])] = z[i]
print zdict
def zfunc(x, y):
return zdict[(x, y)]
X, Y = np.meshgrid(x, y)
print X, Y
#need 2d array of Z
Z = [[zfunc(X[i][j], Y[i][j]) for i in range(0, len(X))] for j in range(0, len(X[0]))]
print Z
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(0, 300.0)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()