Advertisement
EgorYankovsky

Untitled

Jun 2nd, 2023
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. from mpl_toolkits import mplot3d
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. #create 3d axes
  6. fig = plt.figure()
  7. ax = plt.axes(projection='3d')
  8.  
  9. #function for Z values
  10. def f(x, y):
  11. c = [2, 3, 8, 3, 2, 8]
  12. a = [3, -5, 0, 3, -4, 6]
  13. b = [-4, -6, -1, 7, 0, 5]
  14. sum = 0
  15. for i in range(6):
  16. sum += c[i] / (1 + (x - a[i]) ** 2 + (y - b[i]) ** 2)
  17. return sum
  18.  
  19. # x and y values
  20. x = np.linspace(-10, 10, 100)
  21. y = np.linspace(-10, 10, 100)
  22.  
  23. X, Y = np.meshgrid(x, y)
  24. Z = f(X, Y)
  25.  
  26. ax = plt.axes(projection ='3d')
  27. ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
  28. cmap='viridis')
  29. ax.view_init(0, 90)
  30. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement