如何绘制函数中while循环后的几条曲线


def a(t, A, B, C, At, Bt):
while:
calculations
return t, A, B, C, At, Bt

print((t, A, B, C, At, Bt))

返回几个numpy.数组。并以

的形式绘制它们
B, = plt.plot(t, B)
C, = plt.plot(t, C) 
plt.legend(handles=[ B, C, A],
labels=[ 'B', 'C', 'A'])

使用matplotlib的面向对象接口:

from matplotlib import pyplot
t, A, B, C, At, Bt = a(t, A, B, C, At, Bt)
fig, ax = pyplot.subplots()
for array, label in zip([A, B, C], ['A', 'B', 'C']):
ax.plot(t, array, label=label)
ax.legend()

最新更新