I want to create animation using matplotlib.
But there is one problem related to the beauty of visualization. The next value appears abruptly after the previous one. There is no smooth transition. Such animation is good for own use, but it does not look good in a public demonstration.
Example from official documentation
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
np.random.seed(19680801)
HIST_BINS = np.linspace(-4, 4, 100)
data = np.random.randn(1000)
n, _ = np.histogram(data, HIST_BINS)
def prepare_animation(bar_container):
def animate(frame_number):
# simulate new data coming in
data = np.random.randn(1000)
n, _ = np.histogram(data, HIST_BINS)
for count, rect in zip(n, bar_container.patches):
rect.set_height(count)
return bar_container.patches
return animate
fig, ax = plt.subplots()
_, _, bar_container = ax.hist(data, HIST_BINS, lw=1,
ec="yellow", fc="green", alpha=0.5)
ax.set_ylim(top=55)
ani = animation.FuncAnimation(fig, prepare_animation(bar_container), 50,
repeat=False, blit=True)
plt.show()
Can matplotlib provide a smooth transition from one value to another? Here's an example using the flet
library.
Can this be done in matplotlib?