轴线演示

例如,使用plt.axes在主绘图轴中创建嵌入轴。

轴线演示图示

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. # Fixing random state for reproducibility
  4. np.random.seed(19680801)
  5. # create some data to use for the plot
  6. dt = 0.001
  7. t = np.arange(0.0, 10.0, dt)
  8. r = np.exp(-t[:1000] / 0.05) # impulse response
  9. x = np.random.randn(len(t))
  10. s = np.convolve(x, r)[:len(x)] * dt # colored noise
  11. # the main axes is subplot(111) by default
  12. plt.plot(t, s)
  13. plt.axis([0, 1, 1.1 * np.min(s), 2 * np.max(s)])
  14. plt.xlabel('time (s)')
  15. plt.ylabel('current (nA)')
  16. plt.title('Gaussian colored noise')
  17. # this is an inset axes over the main axes
  18. a = plt.axes([.65, .6, .2, .2], facecolor='k')
  19. n, bins, patches = plt.hist(s, 400, density=True)
  20. plt.title('Probability')
  21. plt.xticks([])
  22. plt.yticks([])
  23. # this is another inset axes over the main axes
  24. a = plt.axes([0.2, 0.6, .2, .2], facecolor='k')
  25. plt.plot(t[:len(r)], r)
  26. plt.title('Impulse response')
  27. plt.xlim(0, 0.2)
  28. plt.xticks([])
  29. plt.yticks([])
  30. plt.show()

下载这个示例