plot_stream.py 722 B

1234567891011121314151617181920212223242526272829303132
  1. """Plot streamlines for the 2D field:
  2. u(x,y) = -1 - x:^2 + y
  3. v(x,y) = 1 + x - y:^2
  4. """
  5. from vedo import Points, settings, show
  6. from vedo.pyplot import streamplot
  7. import numpy as np
  8. settings.default_font = "DejavuSansMono"
  9. # a grid with a vector field (U,V):
  10. X, Y = np.mgrid[-5:5 :15j, -4:4 :15j]
  11. U = -1 - X**2 + Y
  12. V = 1 + X - Y**2
  13. # optionally, pick some random points as seeds:
  14. prob_pts = np.random.rand(200, 2)*8 - [4,4]
  15. sp = streamplot(
  16. X,Y,
  17. U,V,
  18. lw=2, # line width in pixel units
  19. direction='forward', # 'both' or 'backward'
  20. probes=prob_pts,
  21. cmap='viridis',
  22. )
  23. sp.add_scalarbar()
  24. pts = Points(prob_pts).ps(5).c('white')
  25. show(sp, pts, __doc__, axes=1, bg='bb').close()