用python绘制动态变化的曲线-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 3600091
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

(365)

  • (365)
文章存档

(8)

(130)

(155)

(50)

(22)

我的朋友
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: python/ruby

2022-05-23 17:08:48

a,b,c = 5,3,4

def tracefunc(theta):

    x = a*np.cos(theta)

    y = b*np.sin(theta)

    return x,y

def linefunc(x,y):

    return [-c,x,c], [0,y,0]

def txtfunc(theta):

    th = 180*theta/np.pi

    x,y = tracefunc(theta)

    lenl = np.sqrt((x c)**2 y**2)

    lenr = np.sqrt((x-c)**2 y**2)

    txt = f'theta={th:.2f}\nlenl={lenl:.2f},lenr={lenr:.2f}\n'

    txt = f'lenl lenr={lenl lenr:.2f}'

    return txt

xlim,ylim = (-a,a), (-b,b)

ts =  np.linspace(0,6.28,200)

class drawani():

    # func为参数方程

    def __init__(self,linefunc,tracefunc,txtfunc,

        ts,xlim,ylim,figsize=(16,9)):

        self.linefunc 外汇跟单gendan5.com= linefunc

        self.tracefunc = tracefunc

        self.txtfunc = txtfunc

        self.fig = plt.figure(figsize=figsize)

        ax = self.fig.add_subplot(autoscale_on=false,

            xlim=xlim,ylim=ylim)

        ax.grid()

        self.line, = ax.plot([],[],'o-',lw=2)

        self.trace, = ax.plot([],[],'-',lw=1)

        self.text = ax.text(0.02,0.85,'',transform=ax.transaxes)

        self.xs, self.ys, self.ts = [],[],ts

        self.run(ts)

    def animate(self,t):

        if(t==self.ts[0]):

            self.xs, self.ys = [],[]

        x,y = self.tracefunc(t)

        self.xs.append(x)

        self.ys.append(y)

        self.line.set_data(self.linefunc(x,y))

        self.trace.set_data(self.xs,self.ys)

        self.text.set_text(self.txtfunc(t))

        return self.line, self.trace, self.text

    def run(self,ts):

        self.ani = animation.funcanimation(self.fig, self.animate, ts, interval=5, blit=true)

        plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)

        plt.show()

    def save(self,savename):

        self.ani.save(savename)

阅读(4698) | 评论(0) | 转发(1) |
0

上一篇:

下一篇:浪漫表白代码

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图