How to do dynamic matplotlib plotting with a fixed pandas dataframe?

后端 未结 2 1814
醉酒成梦
醉酒成梦 2021-01-23 10:57

I have a dataframe called benchmark_returns and strategy_returns. Both have the same timespan. I want to find a way to plot the datapoints in a nice an

2条回答
  •  失恋的感觉
    2021-01-23 11:35

    You can just update the data into the line element like so:

    fig = plt.figure()
    ax = fig.add_subplot(111)
    liner, = ax.plot()
    plt.ion()
    plt.show()
    for i in range(len(benchmark_returns.values)):
        liner.set_ydata(benchmark_returns['Crypto 30'][:i])
        liner.set_xdata(benchmark_returns.index[:i])
        plt.pause(0.01)
    

提交回复
热议问题