冉冉说
黑色阶跃函数可以用 绘制plt.step()。红色和蓝色水平线plt.hlines():import matplotlib.pyplot as pltimport numpy as npN = 150x = np.random.uniform(0.1, 2, N).cumsum()y = np.random.normal(0.01, 0.2, N).cumsum()plt.step(x, y, color='black')for color in ('red', 'blue'): xc = np.linspace(x[0], x[-1], N) + np.random.normal(0, 0.1, N) yc = np.interp(xc, x, y) + np.random.normal(0, 0.1, N) plt.hlines(yc, xc, xc + 5, colors=color, lw=0.5)plt.show()