The x-axis is stationary when the blit parameter is True

37 views Asked by At

There is a sine wave that I want to animate. I have achieved the task, with the "Blit" parameter being set to "False". Curious about what the "Blit" parameter does to the whole animation process, in the context of my code, I set "Blit" to "True". I noticed that while the function returns the Line 2D, the x-axis remains stationary. I wonder if it due to the fact that - when Blit is set to true - it redraws only the artists returned by the function and nothing else.

**Previous Stackoverflow answers I went through ** This is a stackOverflow post I went through and How to animate an expanding circle with blit = true where the Blit parameter is set to True. Going through the said posts, I modified the return statement as follows:

return line, ax But this caused the entire axis to disappear. Can someone point out the mistake in my code?

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


x = np.linspace(0, 10, 100)
y_plot1_fourier = np.sin(x)

x_l_plot = 0
x_u_plot = 5


fig, ax = plt.subplots()
ax.set_xlim([x_l_plot, x_u_plot])
ax.set_ylim(-1.5, 1.5)


line, = ax.plot([], [], label='y_plot1_fourier', c='r', linewidth=2)


def func(n):

    line.set_data(x[:n], y_plot1_fourier[:n])


    if x[n] > x_u_plot - 3:
        ax.set_xlim(x[n] - (x_u_plot - 3), x[n] + 3)
    else:
        ax.set_xlim(x_l_plot, x_u_plot)


    return line, ax


ani = animation.FuncAnimation(fig, func, frames=len(x), interval=200, blit=True)

plt.show()
0

There are 0 answers