Advertisement
Guest User

Untitled

a guest
May 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. plt.figure()
  5. x = np.arange(-4.0, 4.0, 0.03)
  6. y = np.arange(-4.0, 4.0, 0.03)
  7.  
  8. X, Y = np.meshgrid(x, y)
  9.  
  10. coef = 2.0
  11. def f(x, y):
  12. # return 10.0 * 2 + (x**2 - 10 * np.cos(2*np.pi*x)) + (y**2 - 10 * np.cos(2*np.pi*y))
  13. return 10.0 * 2 + (x**2 - 10 * np.cos(2*np.pi*x)) + ((coef*y)**2 - 10 * np.cos(2*np.pi*(coef*y)))
  14.  
  15. def make_Z():
  16. d = len(x)
  17. Z = np.zeros([d, d])
  18. for i in range(d):
  19. for j in range(d):
  20. Z[i, j] = f(x[i], y[j])
  21. return Z
  22.  
  23. # Z = 10.0 * 2 + (X**2 - 10 * np.cos(2*np.pi*X)) + (Y**2 - 10 * np.cos(2*np.pi*Y))
  24. Z = make_Z()
  25. print("Z:{}".format(Z))
  26.  
  27. plt.pcolormesh(X, Y, Z, cmap='hsv') # 等高線図の生成。cmapで色付けの規則を指定する。
  28. #plt.pcolor(X, Y, Z, cmap='hsv') # 等高線図の生成。cmapで色付けの規則を指定する。
  29.  
  30. pp=plt.colorbar (orientation="vertical") # カラーバーの表示
  31. pp.set_label("Label", fontname="Arial", fontsize=24) #カラーバーのラベル
  32.  
  33. plt.xlabel('X', fontsize=24)
  34. plt.ylabel('Y', fontsize=24)
  35.  
  36. plt.savefig('a.pdf')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement