绘制误差条形图子样本

演示 errorevery 关键字,以显示数据的完全精度数据图与很少的误差条。

绘制误差条形图子样本;

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. # example data
  4. x = np.arange(0.1, 4, 0.1)
  5. y = np.exp(-x)
  6. # example variable error bar values
  7. yerr = 0.1 + 0.1 * np.sqrt(x)
  8. # Now switch to a more OO interface to exercise more features.
  9. fig, axs = plt.subplots(nrows=1, ncols=2, sharex=True)
  10. ax = axs[0]
  11. ax.errorbar(x, y, yerr=yerr)
  12. ax.set_title('all errorbars')
  13. ax = axs[1]
  14. ax.errorbar(x, y, yerr=yerr, errorevery=5)
  15. ax.set_title('only every 5th errorbar')
  16. fig.suptitle('Errorbar subsampling for better appearance')
  17. plt.show()

下载这个示例