In this lesson, we are going to do another exercise how to create chart animation using matplotlib in Python.
Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn
Python Code
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
fig.set_tight_layout(True)
print('fig size: {0} DPI, size in inches {1}'.format(fig.get_dpi(), fig.get_size_inches()))
x = np.arange(0, 20, 0.1)
ax.scatter(x, x + np.random.normal(0, 3.0, len(x)))
line, = ax.plot(x, x - 5, 'r-', linewidth=2)
def update(i):
label = 'timestep {0}'.format(i + 1)
line.set_ydata(x - 5 + i)
ax.set_xlabel(label)
# return line, ax
anim = FuncAnimation(fig, update, repeat=True, frames=np.arange(0, 10), interval=500)
plt.show()
Hi JieJenn,
Thank you for your valuable effort. I have learned good things from your site.
I need one help to draw horizontal lines on a button click in the matplotlib chart.
and it should be dragged up and down and pass the Y-values in variable.
Could you help me with simple sample code on this.
Thanks in advance
Rajan
Can you send me your question at YouTube@LearnDataAnalysis.org with a drawing + detailed description illustrate what you are trying to do.