anim_lines.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """Animated plot showing multiple temporal data lines"""
  2. # Copyright (c) 2021, Nicolas P. Rougier. License: BSD 2-Clause*
  3. # Adapted for vedo by M. Musy, February 2021
  4. import numpy as np
  5. from vedo import settings, Line, show
  6. settings.default_font = "Theemim"
  7. # Generate random data
  8. np.random.seed(1)
  9. data = np.random.uniform(0, 1, (25, 100))
  10. X = np.linspace(-1, 1, data.shape[-1])
  11. G = 0.15 * np.exp(-4 * X**2) # use a gaussian as a weight
  12. # Generate line plots
  13. lines = []
  14. for i, d in enumerate(data):
  15. pts = np.c_[X, np.zeros_like(X)+i/10, G*d]
  16. lines.append(Line(pts, lw=3))
  17. # Set up the first frame
  18. axes = dict(xtitle=':Deltat /:mus', ytitle="source", ztitle="")
  19. plt = show(lines, __doc__, axes=axes, elevation=-30, interactive=False, bg='k8')
  20. for i in range(50):
  21. data[:, 1:] = data[:, :-1] # Shift data to the right
  22. data[:, 0] = np.random.uniform(0, 1, len(data)) # Fill-in new values
  23. for line, d in zip(lines, data): # Update data
  24. v = line.points
  25. v[:,2] = G * d
  26. line.points = v
  27. line.cmap('gist_heat_r', v[:,2])
  28. plt.render()
  29. plt.interactive().close()
  30. #############################################################################
  31. # *BSD 2-Clause License
  32. #
  33. # Copyright (c) 2021, Nicolas P. Rougier
  34. # All rights reserved.
  35. #
  36. # Redistribution and use in source and binary forms, with or without
  37. # modification, are permitted provided that the following conditions are met:
  38. #
  39. # * Redistributions of source code must retain the above copyright notice, this
  40. # list of conditions and the following disclaimer.
  41. #
  42. # * Redistributions in binary form must reproduce the above copyright notice,
  43. # this list of conditions and the following disclaimer in the documentation
  44. # and/or other materials provided with the distribution.
  45. #
  46. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  47. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  48. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  49. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  50. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  51. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  54. # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  55. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56. #
  57. # Original version at: https://github.com/rougier/unknown-pleasures