plt9_tick_visibility.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. # 9 - tick_visibility
  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. y = 0.1*x
  15. plt.figure()
  16. plt.plot(x, y, linewidth=10, zorder=1) # set zorder for ordering the plot in plt 2.0.2 or higher
  17. plt.ylim(-2, 2)
  18. ax = plt.gca()
  19. ax.spines['right'].set_color('none')
  20. ax.spines['top'].set_color('none')
  21. ax.spines['top'].set_color('none')
  22. ax.xaxis.set_ticks_position('bottom')
  23. ax.spines['bottom'].set_position(('data', 0))
  24. ax.yaxis.set_ticks_position('left')
  25. ax.spines['left'].set_position(('data', 0))
  26. for label in ax.get_xticklabels() + ax.get_yticklabels():
  27. label.set_fontsize(12)
  28. # set zorder for ordering the plot in plt 2.0.2 or higher
  29. label.set_bbox(dict(facecolor='white', edgecolor='none', alpha=0.8, zorder=2))
  30. plt.show()