python代码画动态图_Python使用matplotlib画动态图

import numpy as np

import matplotlib.pyplot as plt

import math

from scipy.interpolate import make_interp_spline #平滑曲线用的函数

plt.axis([0, 130,-16, 16])

xss=np.array([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130])

ys=np.array([-1.56699, -1.55284, -1.51299, -1.44526, -1.34541, -1.20726, -1.02088, -0.775333, -0.463055,

-0.0576436, 0.475682, 1.15845, 2.00164, 2.99478, 4.13066, 5.38871, 6.73956, 8.10639, 9.43044,

10.6792, 11.8363, 12.8766, 13.7775, 14.5165, 15.0723, 15.4162, 15.5427])

plt.ion()

for k in range(20):

for i in range(101):

A=math.sin(i*math.pi/50)

yss=A*ys

x_smooth = np.linspace(xss.min(), xss.max(), 300)

y_smooth = make_interp_spline(xss, yss)(x_smooth)

plt.cla()

plt.plot(x_smooth, y_smooth,linewidth = '2', color= '#FF0000')

plt.axis([0, 130,-16, 16])

plt.show()

plt.pause(0.005)

if i==0 and k==0:input()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值