# -*- coding: utf-8 -*-
"""
Created on Thu Oct 6 21:18:21 2022
@author: GD005
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
#import matplotlib.animation as animation
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
#指定渲染环境
#%matplotlib auto,
def func(num):
point_ani.set_data(x[num],y[num])
text_pt.set_text("x=%.3f, y=%.3f"%(x[num],y[num]))
return point_ani, text_pt
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
fig = plt.figure(tight_layout=True)
plt.plot(x, y)
point_ani,=plt.plot(x[0],y[0],"ro")
text_pt = plt.text(4, 0.9, '',fontsize=16)
ani = FuncAnimation(fig=fig, func=func,frames=200,interval=100, blit=True)
plt.xlabel('x轴',fontsize=12)
plt.ylabel('y轴',fontsize=12)
plt.title('正弦曲线圆点动画效果图',fontsize=14)
plt.show()