使用Python将数据曲线动起来

13 篇文章 0 订阅
8 篇文章 0 订阅

基本思路:

  1. 首先绘制出几十张静态图片
  2. 然后将静态图片合并为gif文件
  • 首先运行 StaticGraphs.py 文件生成静态图片
import matplotlib.pyplot as plt
from numpy import *
from PIL import Image
#------------------------------------------------------------
xs = linspace(1, 50, 50)
t = linspace(0, 50, 200)
sint = sin(t)
count=0
for x in xs:
    plt.clf()
    plt.plot(t, sint, label='Sinusoidal Curve')
    plt.xlabel('Time (s)')
    plt.ylabel('Amplitude (V)')
    plt.grid(True)
    plt.axis([0, x, -1.5, 1.5])
    plt.savefig(r'.\temp\%d.jpg'%count)
    count = count+1
  • 然后运行 MovingGraph.py 文件自动生成gif图片
from PIL import Image
import os.path
#------------------------------------------------------------
def filedim2gif(giffile=r'.\temp\gif.gif', filedim=[], period=50, last=50):
    if len(filedim) ==0: return 0

    imageDim = []
    for f in filedim:
        imageDim.append(Image.open(os.path.join(r'.\temp', f)))

    duration = [period] * len(imageDim)
    duration[-1] = last

    imageDim[0].save(giffile,\
                     save_all=True,\
                     append_images=imageDim[1:],\
                     duration=duration,
                     loop=False)

    print('Save GIF: %s'%giffile)
    return 0

count = eval(input('图片数量:'))
filedimls = []
for i in range(count):
    filedimls.append('{}.jpg'.format(i))
filedim2gif(filedim=filedimls,period=count, last=count)
input('任意键继续...')

如需源文件点击此处下载

参考资料:TsinghuaJoking 如何使用Python语言将测量数据曲线动起来?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_43964993

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值