Matplotlib में एनिमेशन का उपयोग करके प्लॉट शीर्षक अपडेट करने के लिए, हम निम्नलिखित चरण ले सकते हैं:
-
<ली>फिगर आकार सेट करें और सबप्लॉट के बीच और आसपास पैडिंग समायोजित करें।ली>
<ली>figure() मेथड का उपयोग करके एक नया फिगर बनाएं या मौजूदा फिगर सक्रिय करें।ली>
<ली>numpy का उपयोग करके x और y डेटा बिंदु बनाएं।ली>
<ली>वर्तमान अक्ष प्राप्त करें।ली>
<ली>text() मेथड का उपयोग करके अक्ष पर टेक्स्ट जोड़ें।ली>
<ली>एक एनिमेट मेथड जोड़ें जिसका उपयोग फ़ंक्शन को बार-बार कॉल करके एनिमेशन बनाने के लिए किया जा सकता है।ली>
<ली>फिगर प्रदर्शित करने के लिए show() मेथड का उपयोग करें।ली>
उदाहरण
import numpy as np
from matplotlib import pyplot as plt, animation
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
x = np.linspace(-10, 10, 1000)
y = np.sin(x)
plt.plot(x, y)
ax = plt.gca()
ax.text(0.5, 1.100, "y=sin(x)", bbox={'facecolor': 'red',
'alpha': 0.5, 'pad': 5},
transform=ax.transAxes, ha="center")
def animate(frame):
ax.text(0.5, 1.100, "y=sin(x), frame: %d" % frame,
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 5},
transform=ax.transAxes, ha="center")
ani = animation.FuncAnimation(fig, animate, interval=100,
frames=10, repeat=True)
plt.show()
आउटपुट
