import matplotlib.pyplot as plt import random plt.title('随机折线图') # 设置图名 position = 0 walk = [position] steps = 1000 for i in range(steps): step = 1 if random.randint(0,1) else -1 position += step walk.append(position) plt.plot(walk[:200]) # 绘制200点 plt.show()