scatter2.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Scatter plot of a gaussian distribution
  2. # with varying color and point sizes
  3. from vedo import Text2D, Plotter
  4. from vedo.pyplot import plot
  5. import numpy as np
  6. n = 500
  7. x = np.random.randn(n)
  8. y = np.random.randn(n)
  9. # Define what size must have each marker:
  10. marker_sizes = np.sin(2*x)/8
  11. # Define a (r,g,b) list of colors for each marker:
  12. marker_cols = np.c_[np.cos(2*x), np.zeros(n), np.zeros(n)]
  13. txt0 = Text2D("A scatter plot of a\n2D gaussian distribution")
  14. fig0 = plot(
  15. x, y,
  16. lw=0, # no joining of lines
  17. marker="*", # marker style
  18. xtitle="variable A",
  19. ytitle="variable B",
  20. grid=False,
  21. )
  22. txt1 = Text2D("marker size proportional to sin(2x) ")
  23. fig1 = plot(
  24. x, y,
  25. lw=0,
  26. marker="*",
  27. ms=marker_sizes, # VARIABLE marker sizes
  28. mc='purple5', # same fixed color for markers
  29. grid=False,
  30. )
  31. txt2 = Text2D("marker size proportional to sin(2x)\nred level proportional to cos(2x)")
  32. fig2 = plot(
  33. x, y, lw=0,
  34. marker=">",
  35. ms=marker_sizes, # VARIABLE marker sizes
  36. mc=marker_cols, # VARIABLE marker colors
  37. grid=False,
  38. )
  39. plt = Plotter(N=3, size=(1800,500))
  40. plt.at(0).show(fig0, txt0)
  41. plt.at(1).show(fig1, txt1)
  42. plt.at(2).show(fig2, txt2, zoom=1.2)
  43. plt.interactive().close()