test_fxy_bessel1.py 973 B

123456789101112131415161718192021222324252627282930313233343536
  1. import numpy as np
  2. from scipy import special
  3. from scipy.special import jn_zeros
  4. from vedo import show
  5. from vedo.pyplot import plot
  6. Nr = 2
  7. Nθ = 3
  8. def f(x, y):
  9. d2 = x ** 2 + y ** 2
  10. if d2 > 1:
  11. return np.nan
  12. else:
  13. r = np.sqrt(d2)
  14. θ = np.arctan2(y, x)
  15. kr = jn_zeros(Nθ, 4)[Nr]
  16. return special.jn(Nθ, kr * r) * np.cos(Nθ * θ)
  17. p = plot(
  18. f, xlim=[-1, 1], ylim=[-1, 1], zlim=[-1, 1],
  19. show_nan=False, bins=(100, 100),
  20. )
  21. # Unpack the plot objects to customize them
  22. objs = p.unpack()
  23. # objs[1].off() # turn off the horizontal levels
  24. # objs[0].lw(1) # set line width
  25. objs[0].lighting('off') # style of mesh lighting "glossy", "plastic"..
  26. zvals = objs[0].vertices[:, 2] # get the z values
  27. objs[0].cmap("RdBu", zvals, vmin=-0.0, vmax=0.4) # apply the color map
  28. sc = objs[0].add_scalarbar3d(title="Bessel Function").scalarbar
  29. print("range:", zvals.min(), zvals.max())
  30. show(p, sc, viewup="z").close()