• fluent鱼儿游动,保存为gif动图,python代码


    # -*- coding: utf-8 -*-
    """
    Created on Fri Nov 11 18:41:30 2022
    fluent鱼儿游动,保存为gif动图
    @author: in
    """
    
    import matplotlib
    matplotlib.use('Agg') # 只绘图保存,不显示图片,一定要加在import后面
    import numpy as np
    import matplotlib.pyplot as plt
    import imageio
    import pandas as pd
    from matplotlib.pyplot import MultipleLocator#从pyplot导入MultipleLocator类,这个类用于设置刻度间隔
    
    
    path = r'D:\20221112fish\move\coordinate.xlsx'
    data = pd.DataFrame(pd.read_excel(path))
    output_path = r'D:\20221112fish\move\test.gif'#保存gif的路径及名字
    print(data.index)#获取行的索引名称
    print(data.columns)#获取列的索引名称
    x = data['x'].values.tolist()#获取列名为姓名这一列的内容
    t = data['t'].values.tolist()#获取列名为姓名这一列的内容
    b = data['b'].values.tolist()#获取列名为姓名这一列的内容
    m = data['m'].values.tolist()
    
    
    
    time = 1.8
    step = 0.04
    image_list = []
    pig = 0
    zdfd = 1
    def fish(x,t,dt,zdfd):
        k = 2*3.1415926/0.95
        w = 2*3.1415926*1
        return zf*(0.02-0.08*x+0.16*x*x)*((np.sin(k*x-w*t))-(np.sin(k*x-w*(t-dt))))
    for td in np.arange(0.01,time,step):
        pig = pig+1
        ty = []
        my = []
        by = []
        for xp in range(0,len(x)):
            dy = fish(x[xp],td,step,zdfd)
            t[xp] = t[xp]+dy
            m[xp] = m[xp]+dy
            b[xp] = b[xp]+dy
        plt.plot(x, t)
        plt.plot(x, b)
        plt.plot(x, m)
        '''设置数据在四周的坐标显示'''
        plt.tick_params(top=True,bottom=True,left=True,right=True)
        plt.tick_params(labeltop=True,labelleft=True,labelright=True,labelbottom=True)
        plt.grid( color = 'black',linestyle='-.',linewidth = 1)#设置网格线
        plt.ylim(-0.3,0.3)#设置y轴的最大值和最小值
    #    plt.xlim(-0.5,11)#设置x轴的最大值和最小值
        
    #    '''设置x,y轴的间隔'''
    #    x_major_locator=MultipleLocator(0.1)
    #    #把x轴的刻度间隔设置为,并存在变量里
    #    y_major_locator=MultipleLocator(0.05)
    #    #把y轴的刻度间隔设置为,并存在变量里
    #    ax=plt.gca()
    #    #ax为两条坐标轴的实例
    #    ax.xaxis.set_major_locator(x_major_locator)
    #    #把x轴的主刻度设置为0.1
    #    ax.yaxis.set_major_locator(y_major_locator)
    #    #把y轴的主刻度设置为0.05
    
        plt.savefig('temp.png')
        img = cv2.imread('temp.png')
        image_list.append(imageio.imread('temp.png'))
        plt.pause(0.1)
        plt.close()
    imageio.mimsave(output_path, image_list, 'GIF', duration=0.35)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75

    excel的链接:https://download.csdn.net/download/weixin_43245453/86996059
    在这里插入图片描述

  • 相关阅读:
    简单了解一下国产GPU
    Three.js动效(第15辑):让前端手撕UI,拳打后端的效果。
    小游戏《羊了个羊》爆火,如何快速开始微信小程序开发?
    【TIM定时器】
    组合设计模式
    c++字符串相关接口
    在centos7上搭建hadoop大数据平台
    8、智慧交通项目(1)
    串口中断与环形队列——高级应用
    中高级Java程序员,你不得不掌握的基本功,挑战20k+
  • 原文地址:https://blog.csdn.net/weixin_43245453/article/details/127838338