plot_fxy1.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. '''Draw a z = f(x,y) surface specified as
  2. a string or as a reference to an external function.
  3. Red points indicate where the function does not exist!'''
  4. from vedo import dataurl, sin, cos, log, show, Text2D
  5. from vedo.pyplot import plot
  6. doc = Text2D(__doc__, pos='bottom-left', c='darkgreen', font='Quikhand')
  7. ############################################################### REAL
  8. def f(x, y):
  9. return sin(2*x*y) * cos(3*y)/2
  10. f1 = plot(f, c='summer') # use a colormap
  11. # red dots are shown where the function does not exist (y>x):
  12. def f(x, y):
  13. return sin(3*x) * log(x-y)/3
  14. f2 = plot(f, texture=dataurl+'textures/paper3.jpg')
  15. # specify x and y ranges and z vertical limits:
  16. def f(x, y):
  17. return log(x**2+y**2-1)
  18. f3 = plot(
  19. f,
  20. xlim=[-2,2],
  21. ylim=[-1,8],
  22. zlim=[-1,None],
  23. texture=dataurl+'textures/paper1.jpg',
  24. )
  25. show([(f1, 'y = sin(2*x*y) * cos(3*y) /2', doc),
  26. (f2, 'y = sin(3*x)*log(x-y)/3'),
  27. (f3, 'y = log(x**2+y**2-1)'),
  28. ], N=3, sharecam=False,
  29. ).close()
  30. ############################################################## COMPLEX
  31. comment = """Vertical axis shows the real part of complex z:
  32. z = sin(log(x:doty))
  33. Color map the value of the imaginary part
  34. (green=positive, purple=negative)"""
  35. plt = plot(lambda x,y: sin(log(x*y))/25, mode='complex', bins=(51,51))
  36. show(plt, comment, viewup='z').close()