0

I have about 8 months worth of hourly data that I want to plot in an animation style. I am currently able to do that, however it gets extremely slow as the quantity of data increases. Note that I have even set the interval to only 1ms! Is there anyway to ensure that the animation doesn't slow down? Furthermore, how can I plot multiple lines at the same time in this style?

Here is my code so far:

x = benchmark_returns.index
y = benchmark_returns['Crypto 30'] 
#Would preferrably like to plot 
#benchmark_returns[['Crypto 30', 'NASDAQ', 'Dow Jones 30', 'S&P 500']] at the same time

fig, ax = plt.subplots()
line, = ax.plot(x, y, color='k')

def update(num, x, y, line):
    line.set_data(x[:num], y[:num])
    return line,


ani = animation.FuncAnimation(fig, update,  fargs=[x, y, line],
                              interval = 1, blit=True)
plt.show()

Here is an example of my dataframe:

                     Crypto 30  Dow Jones 30  NASDAQ  S&P 500
2019-06-09 00:00:00  100.00000         100.0   100.0    100.0
2019-06-09 01:00:00   95.78653         100.0   100.0    100.0
2019-06-09 02:00:00   95.78653         100.0   100.0    100.0
2019-06-09 03:00:00   95.78653         100.0   100.0    100.0
2019-06-09 04:00:00   95.78653         100.0   100.0    100.0
2019-06-09 05:00:00   95.78653         100.0   100.0    100.0
2019-06-09 06:00:00   95.78653         100.0   100.0    100.0
2019-06-09 07:00:00   95.78653         100.0   100.0    100.0
2019-06-09 08:00:00   95.78653         100.0   100.0    100.0
2019-06-09 09:00:00   95.78653         100.0   100.0    100.0
3
  • Please provide a minimal reproducible example. That is provide some sample data for x and y. Commented Mar 10, 2020 at 12:59
  • I just have, please feel free to have a look. Thank you Commented Mar 10, 2020 at 13:34
  • The sample data should be representative for your problem and as far as I understand it's the size of the data that causes trouble. The sample data does not need to be in literal format, you can use any generating code that results in the same problems. For example x = np.arange(1_000_000); y = np.sin(x/10). Commented Mar 10, 2020 at 18:00

1 Answer 1

1

Displaying an animation with plt.show() is limited by the speed with which the computer can redraw the plot - consequently the interval will not necessarily dictate the actual rate at which the animation will update. Saving the animation via

ani.save("animation.mp4")

or similar will allow you to view the animation at the specified speed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.