Facebook
From Bethan Donovan , 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 61
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Wed Nov 25 17:48:06 2020
  5.  
  6. @author: bethandonovan
  7. """
  8.  
  9. # This import registers the 3D projection, but is otherwise unused.
  10. from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import
  11.  
  12. import matplotlib.pyplot as plt
  13. from matplotlib import cm
  14. from matplotlib.ticker import LinearLocator, FormatStrFormatter
  15. import numpy as np
  16.  
  17.  
  18. fig = plt.figure()
  19. ax = fig.gca(projection='3d')
  20.  
  21. # Make data.
  22. X = np.arange(-80, 80, 10)
  23. Y = np.arange(-80, 80, 10)
  24. x, y = np.meshgrid(X, Y)
  25. Z_X = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  26. Z_Y = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  27. Z = np.empty([17,17])
  28.  
  29.  
  30. for n1 in range(17):
  31.     for n2 in range(17):
  32.         Zz = np.sqrt(Z_X[n1]**2+Z_Y[n2]**2)
  33.         Z[n1,n2]= Zz
  34.  
  35.  
  36.  
  37.  
  38.  
  39.    
  40.  
  41.  
  42. # Plot the surface.
  43. #surf = ax.plot_surface(x, y, Z, cmap=cm.coolwarm,
  44. #                       linewidth=0, antialiased=False)
  45.  
  46. # Customize the z axis.
  47. ax.set_zlim(-1.01, 1.01)
  48. ax.zaxis.set_major_locator(LinearLocator(10))
  49. ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
  50.  
  51. # Add a color bar which maps values to colors.
  52. fig.colorbar(surf, shrink=0.5, aspect=5)
  53.  
  54. plt.show()