Advertisement
furas

Python - matplot - plot_surface

Jun 3rd, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. from mpl_toolkits.mplot3d import Axes3D
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5. data = np.array([
  6.     [0, 0, 1],
  7.     [0, 1, 1],
  8.     [0, 2, 1],
  9.     [1, 0, 2],
  10.     [1, 1, 3],
  11.     [1, 2, 2],
  12.     [2, 0, 2],
  13.     [2, 1, 2],
  14.     [2, 2, 2],
  15. ])
  16.  
  17. print('data shape:', data.shape)
  18. n = data.shape[0]   # number of points
  19. M = int(np.sqrt(n)) # square M*M = n
  20.  
  21. X = data[:,0]
  22. Y = data[:,1]
  23. Z = data[:,2]
  24.  
  25. X = X.reshape(M, M)
  26. Y = Y.reshape(M, M)
  27. Z = Z.reshape(M, M)
  28.  
  29. print('sX:', X.shape)
  30. print('X:', X)
  31. print('sY:', Y.shape)
  32. print('Y:', Y)
  33. print('sZ:', Z.shape)
  34. print('Z:', Z)
  35.  
  36. fig = plt.figure()
  37. ax = fig.gca(projection='3d')
  38.  
  39. surf = ax.plot_surface(X, Y, Z)
  40.  
  41. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement