Nan测试

示例:插入Nan的简单线条图。

Nan的简单线条图

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. t = np.arange(0.0, 1.0 + 0.01, 0.01)
  4. s = np.cos(2 * 2*np.pi * t)
  5. t[41:60] = np.nan
  6. plt.subplot(2, 1, 1)
  7. plt.plot(t, s, '-', lw=2)
  8. plt.xlabel('time (s)')
  9. plt.ylabel('voltage (mV)')
  10. plt.title('A sine wave with a gap of NaNs between 0.4 and 0.6')
  11. plt.grid(True)
  12. plt.subplot(2, 1, 2)
  13. t[0] = np.nan
  14. t[-1] = np.nan
  15. plt.plot(t, s, '-', lw=2)
  16. plt.title('Also with NaN in first and last point')
  17. plt.xlabel('time (s)')
  18. plt.ylabel('more nans')
  19. plt.grid(True)
  20. plt.tight_layout()
  21. plt.show()

下载这个示例