plt4_figure.py 730 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. # 4 - figure
  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. x = np.linspace(-3, 3, 50)
  14. y1 = 2*x + 1
  15. y2 = x**2
  16. plt.figure()
  17. plt.plot(x, y1)
  18. plt.figure(num=3, figsize=(8, 5),)
  19. plt.plot(x, y2)
  20. # plot the second curve in this figure with certain parameters
  21. plt.plot(x, y1, color='red', linewidth=1.0, linestyle='--')
  22. plt.show()