-1

I have this program which will solve a system of differential equations in such way that two values xi, yi are produced each time a for loop iterates. Is there some way i could plot these values as they are produced instead of waiting for the computation to finish, then plotting them all?

4

2 回答 2

0

假设您的算法如下所示:

import matplotlib

x_list = []
y_list = []
while True:
    xi, yi = compute() # calculates your xi and yi value
    if converged(xi, yi):
        break
    # capture history of your xi and yi
    x_list.append(xi)
    y_list.append(yi)

matplotlib.pyplot.plot(x, y) # create a graph representing x and y
于 2012-04-15T19:26:48.880 回答
0

您可能想看看 matplotlib ( http://matplotlib.sourceforge.net/ ) 或 gnuplot.py ( http://gnuplot-py.sourceforge.net/ )。完成后,我使用这些来绘制数据,但我看不出为什么在生成数据时不能这样做。但是,根据循环执行的速度,这可能会减慢整个程序的速度。

gnuplot 可能不再维护,但我一直在使用它,没有任何问题。

于 2012-04-15T19:23:01.923 回答