Advertisement
Abhisek92

plot

Aug 15th, 2023 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. from mpl_toolkits.mplot3d import Axes3D
  2. import cmocean.cm as cmo
  3. from matplotlib.path import Path
  4. import matplotlib.patches as patches
  5. from matplotlib import pyplot as plt
  6. import numpy as np
  7. from numpy import polyfit, polyval
  8.  
  9. q = np.linspace(0.0000001, 0.9999999, num=10000)
  10. x = (1 - q) # 1 - ratio
  11. y = (1 + q) # 1 + ratio
  12. theta_c = np.rad2deg(np.arctan((x ** 2) / (x + (q ** 2)))) #theta_c
  13. p1 = 1 / y # 1 / y
  14. p2 = q * p1 # p1 * ratio
  15. h_c = -(p1 * np.log2(p1)) - (p2 * np.log2(p2)) #h_c
  16. alpha = np.rad2deg(np.arctan((theta_c / 45) / h_c))
  17.  
  18. # xx, yy = np.meshgrid(h_c, theta_c)
  19. params = polyfit(h_c, theta_c, 8, full=False, cov=False)
  20. def fun(dat):
  21.     return polyval(params, dat)
  22.  
  23. xx = np.linspace(0, 1, 1000)
  24. yy = np.linspace(0, 1, 1000)
  25. xx, yy = np.meshgrid(xx, yy)
  26. zz = np.arctan2(xx, yy) / (2 * np.pi)
  27. zz[(45*yy)>fun(xx)] = np.nan
  28. # dd = zz - yy
  29. # dd[yy>zz] = np.nan
  30. # dd = -dd
  31.  
  32. z1_mask = np.logical_and((np.logical_and((0 <= h_c), (h_c < 0.3))), np.logical_and((30<= theta_c), (theta_c <= 45)))
  33. z2_mask = np.logical_and((np.logical_and((0.3 <= h_c), (h_c < 0.5))), np.logical_and((30<= theta_c), (theta_c <= 45)))
  34. z3_mask = np.logical_and((np.logical_and((0.5 <= h_c), (h_c < 0.7))), np.logical_and((30<= theta_c), (theta_c <= 45)))
  35. z4_mask = np.logical_and((np.logical_and((0.7 <= h_c), (h_c <= 1))), np.logical_and((30<= theta_c), (theta_c <= 45)))
  36. z5_mask = np.logical_and((np.logical_and((0.7 <= h_c), (h_c <= 1))), np.logical_and((15<= theta_c), (theta_c < 30)))
  37. z6_mask = np.logical_and((np.logical_and((0.7 <= h_c), (h_c <= 1))), np.logical_and((0<= theta_c), (theta_c < 15)))
  38. z0_mask = np.logical_and((np.logical_and((0 <= h_c), (h_c < 0.7))), np.logical_and((0<= theta_c), (theta_c < 30)))
  39.  
  40. fig = plt.figure(figsize=(10,10))
  41. ax = plt.subplot(1, 1, 1)
  42. ax.plot(h_c[z1_mask], theta_c[z1_mask], linewidth=7, color='#fde725')
  43. ax.plot(h_c[z2_mask], theta_c[z2_mask], linewidth=7, color='#7ad151')
  44. ax.plot(h_c[z3_mask], theta_c[z3_mask], linewidth=7, color='#22a884')
  45. ax.plot(h_c[z4_mask], theta_c[z4_mask], linewidth=7, color='#2a788e')
  46. ax.plot(h_c[z5_mask], theta_c[z5_mask], linewidth=7, color='#414487')
  47. ax.plot(h_c[z6_mask], theta_c[z6_mask], linewidth=7, color='#440154')
  48.  
  49. # c = ax.pcolormesh(h_c, theta_c, distances, shading='auto', cmap='viridis', alpha=0.7)
  50. c = ax.imshow(zz, extent=(0, 1, 0, 45), aspect='auto', origin='lower', cmap=cmo.ice_r)
  51.  
  52. ax.plot([0, 0.765], [0, 32], color='red', linewidth=2, linestyle='-')
  53. ax.plot([0, 1], [0, 0], color='red', linewidth=2, linestyle='-')
  54.  
  55. plt.ylim([0, 45])
  56. plt.xlim([0, 1])
  57. plt.xticks(fontsize=15)
  58. plt.yticks(fontsize=15)
  59. ax.set_ylabel(r'$\theta_c$ [deg]', fontsize=20)
  60. ax.set_xlabel('$H_c$', fontsize=20)
  61. plt.savefig("foo.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement