18_plot.py 919 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. """
  5. Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
  6. """
  7. from __future__ import print_function
  8. import pandas as pd
  9. import numpy as np
  10. import matplotlib.pyplot as plt
  11. # plot data
  12. # Series
  13. data = pd.Series(np.random.randn(1000), index=np.arange(1000))
  14. data = data.cumsum()
  15. ##data.plot()
  16. # DataFrame
  17. data = pd.DataFrame(np.random.randn(1000, 4), index=np.arange(1000), columns=list("ABCD"))
  18. data = data.cumsum()
  19. # plot methods:
  20. # 'bar', 'hist', 'box', 'kde', 'area', scatter', hexbin', 'pie'
  21. ax = data.plot.scatter(x='A', y='B', color='DarkBlue', label="Class 1")
  22. data.plot.scatter(x='A', y='C', color='LightGreen', label='Class 2', ax=ax)
  23. plt.show()