plt10_scatter.py 751 B

1234567891011121314151617181920212223242526272829
  1. # View more python tutorials on my Youtube and Youku channel!!!
  2. # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
  3. # Youku video tutorial: http://i.youku.com/pythontutorial
  4. # 10 - scatter
  5. """
  6. Please note, this script is for python3+.
  7. If you are using python2+, please modify it accordingly.
  8. Tutorial reference:
  9. http://www.scipy-lectures.org/intro/matplotlib/matplotlib.html
  10. """
  11. import matplotlib.pyplot as plt
  12. import numpy as np
  13. n = 1024 # data size
  14. X = np.random.normal(0, 1, n)
  15. Y = np.random.normal(0, 1, n)
  16. T = np.arctan2(Y, X) # for color later on
  17. plt.scatter(X, Y, s=75, c=T, alpha=.5)
  18. plt.xlim(-1.5, 1.5)
  19. plt.xticks(()) # ignore xticks
  20. plt.ylim(-1.5, 1.5)
  21. plt.yticks(()) # ignore yticks
  22. plt.show()