简 介: 本文给出了将matlibplot的图片组合成动图对应的子程序。

关键词PlotGIF动图

#mermaid-svg-AdyfyNiu6xFaA0vb .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .label text{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .node rect,#mermaid-svg-AdyfyNiu6xFaA0vb .node circle,#mermaid-svg-AdyfyNiu6xFaA0vb .node ellipse,#mermaid-svg-AdyfyNiu6xFaA0vb .node polygon,#mermaid-svg-AdyfyNiu6xFaA0vb .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-AdyfyNiu6xFaA0vb .node .label{text-align:center;fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .node.clickable{cursor:pointer}#mermaid-svg-AdyfyNiu6xFaA0vb .arrowheadPath{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-AdyfyNiu6xFaA0vb .flowchart-link{stroke:#333;fill:none}#mermaid-svg-AdyfyNiu6xFaA0vb .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-AdyfyNiu6xFaA0vb .edgeLabel rect{opacity:0.9}#mermaid-svg-AdyfyNiu6xFaA0vb .edgeLabel span{color:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-AdyfyNiu6xFaA0vb .cluster text{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-AdyfyNiu6xFaA0vb .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-AdyfyNiu6xFaA0vb text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-AdyfyNiu6xFaA0vb .actor-line{stroke:grey}#mermaid-svg-AdyfyNiu6xFaA0vb .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-AdyfyNiu6xFaA0vb #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .sequenceNumber{fill:#fff}#mermaid-svg-AdyfyNiu6xFaA0vb #sequencenumber{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb #crosshead path{fill:#333;stroke:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .messageText{fill:#333;stroke:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-AdyfyNiu6xFaA0vb .labelText,#mermaid-svg-AdyfyNiu6xFaA0vb .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-AdyfyNiu6xFaA0vb .loopText,#mermaid-svg-AdyfyNiu6xFaA0vb .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-AdyfyNiu6xFaA0vb .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-AdyfyNiu6xFaA0vb .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-AdyfyNiu6xFaA0vb .noteText,#mermaid-svg-AdyfyNiu6xFaA0vb .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-AdyfyNiu6xFaA0vb .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-AdyfyNiu6xFaA0vb .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-AdyfyNiu6xFaA0vb .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-AdyfyNiu6xFaA0vb .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .section{stroke:none;opacity:0.2}#mermaid-svg-AdyfyNiu6xFaA0vb .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-AdyfyNiu6xFaA0vb .section2{fill:#fff400}#mermaid-svg-AdyfyNiu6xFaA0vb .section1,#mermaid-svg-AdyfyNiu6xFaA0vb .section3{fill:#fff;opacity:0.2}#mermaid-svg-AdyfyNiu6xFaA0vb .sectionTitle0{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .sectionTitle1{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .sectionTitle2{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .sectionTitle3{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-AdyfyNiu6xFaA0vb .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .grid path{stroke-width:0}#mermaid-svg-AdyfyNiu6xFaA0vb .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-AdyfyNiu6xFaA0vb .task{stroke-width:2}#mermaid-svg-AdyfyNiu6xFaA0vb .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .taskText:not([font-size]){font-size:11px}#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-AdyfyNiu6xFaA0vb .task.clickable{cursor:pointer}#mermaid-svg-AdyfyNiu6xFaA0vb .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-AdyfyNiu6xFaA0vb .taskText0,#mermaid-svg-AdyfyNiu6xFaA0vb .taskText1,#mermaid-svg-AdyfyNiu6xFaA0vb .taskText2,#mermaid-svg-AdyfyNiu6xFaA0vb .taskText3{fill:#fff}#mermaid-svg-AdyfyNiu6xFaA0vb .task0,#mermaid-svg-AdyfyNiu6xFaA0vb .task1,#mermaid-svg-AdyfyNiu6xFaA0vb .task2,#mermaid-svg-AdyfyNiu6xFaA0vb .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutside0,#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutside2{fill:#000}#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutside1,#mermaid-svg-AdyfyNiu6xFaA0vb .taskTextOutside3{fill:#000}#mermaid-svg-AdyfyNiu6xFaA0vb .active0,#mermaid-svg-AdyfyNiu6xFaA0vb .active1,#mermaid-svg-AdyfyNiu6xFaA0vb .active2,#mermaid-svg-AdyfyNiu6xFaA0vb .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-AdyfyNiu6xFaA0vb .activeText0,#mermaid-svg-AdyfyNiu6xFaA0vb .activeText1,#mermaid-svg-AdyfyNiu6xFaA0vb .activeText2,#mermaid-svg-AdyfyNiu6xFaA0vb .activeText3{fill:#000 !important}#mermaid-svg-AdyfyNiu6xFaA0vb .done0,#mermaid-svg-AdyfyNiu6xFaA0vb .done1,#mermaid-svg-AdyfyNiu6xFaA0vb .done2,#mermaid-svg-AdyfyNiu6xFaA0vb .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-AdyfyNiu6xFaA0vb .doneText0,#mermaid-svg-AdyfyNiu6xFaA0vb .doneText1,#mermaid-svg-AdyfyNiu6xFaA0vb .doneText2,#mermaid-svg-AdyfyNiu6xFaA0vb .doneText3{fill:#000 !important}#mermaid-svg-AdyfyNiu6xFaA0vb .crit0,#mermaid-svg-AdyfyNiu6xFaA0vb .crit1,#mermaid-svg-AdyfyNiu6xFaA0vb .crit2,#mermaid-svg-AdyfyNiu6xFaA0vb .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-AdyfyNiu6xFaA0vb .activeCrit0,#mermaid-svg-AdyfyNiu6xFaA0vb .activeCrit1,#mermaid-svg-AdyfyNiu6xFaA0vb .activeCrit2,#mermaid-svg-AdyfyNiu6xFaA0vb .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-AdyfyNiu6xFaA0vb .doneCrit0,#mermaid-svg-AdyfyNiu6xFaA0vb .doneCrit1,#mermaid-svg-AdyfyNiu6xFaA0vb .doneCrit2,#mermaid-svg-AdyfyNiu6xFaA0vb .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-AdyfyNiu6xFaA0vb .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-AdyfyNiu6xFaA0vb .milestoneText{font-style:italic}#mermaid-svg-AdyfyNiu6xFaA0vb .doneCritText0,#mermaid-svg-AdyfyNiu6xFaA0vb .doneCritText1,#mermaid-svg-AdyfyNiu6xFaA0vb .doneCritText2,#mermaid-svg-AdyfyNiu6xFaA0vb .doneCritText3{fill:#000 !important}#mermaid-svg-AdyfyNiu6xFaA0vb .activeCritText0,#mermaid-svg-AdyfyNiu6xFaA0vb .activeCritText1,#mermaid-svg-AdyfyNiu6xFaA0vb .activeCritText2,#mermaid-svg-AdyfyNiu6xFaA0vb .activeCritText3{fill:#000 !important}#mermaid-svg-AdyfyNiu6xFaA0vb .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-AdyfyNiu6xFaA0vb g.classGroup text .title{font-weight:bolder}#mermaid-svg-AdyfyNiu6xFaA0vb g.clickable{cursor:pointer}#mermaid-svg-AdyfyNiu6xFaA0vb g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-AdyfyNiu6xFaA0vb g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-AdyfyNiu6xFaA0vb .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-AdyfyNiu6xFaA0vb .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-AdyfyNiu6xFaA0vb .dashed-line{stroke-dasharray:3}#mermaid-svg-AdyfyNiu6xFaA0vb #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb .commit-id,#mermaid-svg-AdyfyNiu6xFaA0vb .commit-msg,#mermaid-svg-AdyfyNiu6xFaA0vb .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-AdyfyNiu6xFaA0vb g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-AdyfyNiu6xFaA0vb g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-AdyfyNiu6xFaA0vb g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-AdyfyNiu6xFaA0vb .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-AdyfyNiu6xFaA0vb .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-AdyfyNiu6xFaA0vb .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-AdyfyNiu6xFaA0vb .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-AdyfyNiu6xFaA0vb .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-AdyfyNiu6xFaA0vb .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-AdyfyNiu6xFaA0vb .edgeLabel text{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-AdyfyNiu6xFaA0vb .node circle.state-start{fill:black;stroke:black}#mermaid-svg-AdyfyNiu6xFaA0vb .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-AdyfyNiu6xFaA0vb #statediagram-barbEnd{fill:#9370db}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-state .divider{stroke:#9370db}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-AdyfyNiu6xFaA0vb .note-edge{stroke-dasharray:5}#mermaid-svg-AdyfyNiu6xFaA0vb .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-AdyfyNiu6xFaA0vb .error-icon{fill:#522}#mermaid-svg-AdyfyNiu6xFaA0vb .error-text{fill:#522;stroke:#522}#mermaid-svg-AdyfyNiu6xFaA0vb .edge-thickness-normal{stroke-width:2px}#mermaid-svg-AdyfyNiu6xFaA0vb .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-AdyfyNiu6xFaA0vb .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-AdyfyNiu6xFaA0vb .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-AdyfyNiu6xFaA0vb .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-AdyfyNiu6xFaA0vb .marker{fill:#333}#mermaid-svg-AdyfyNiu6xFaA0vb .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-AdyfyNiu6xFaA0vb {color: rgba(0, 0, 0, 0.75);font: ;}

问题来源
文章目录
附件程序
子程序
headm.py
tsdraw程序
相关博文

§01 问题来源


  今天在推文 应用在机器学习中的聚类数据集产生方法 中的后面有人留言询问:

  • m0_60067953 :headm这个包怎么安装啊 还有pltgif = PlotGIF()也报错,没有这个函数

  下面将PlotGIF() 中对应的程序给出。

§02 附件程序


一、子程序

  首先在headm.py中给出了平时应用程序时常应用到连接。如下。

  对于PlotGIF()相关是其中的 tsdraw Python程序。因此在引入的时候,只需要将tsdraw 引入程序即可。 tsdraw在后面给出。

1、headm.py

import sys, os
sys.path.append(r'd:\python\teasoft')
STDFILE = open(r'd:\python\std.txt', 'a', 1)
sysstderr = sys.stderr
sysstdout = sys.stdout
sys.stderr = STDFILE
sys.stdout = STDFILEfrom threading import Thread
import time, math, winsound, clipboard, random
from numpy import *from tsmodule.tspdata   import *
from tsmodule.tspyt     import *
from tsmodule.tscmd     import *
from tsmodule.tsdopop   import *
from tsmodule.tsdraw    import *
import tsmodule.tsconfig
import matplotlib.pyplot as pltdef setpltrange(posx=2000, posy=550, width=800, height=640):cmfw = plt.get_current_fig_manager().windowcmfw.setGeometry(posx, posy, width, height)setpltrange()
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

2、tsdraw程序

  下面给出了tsdraw程序。注意,将其中的````printf 都替换成 print 即可。

  实现转换成将 matlibplot 的图片转换成GIF主要是其中 PlotGIF类。具体使用可以参见前面的应用在机器学习中的聚类数据集产生方法 中给出的应用举例即可。

from PIL import Imageclass PlotGIF(object):def __init__(self, gifdir=r'd:\temp\GIF'):self.gifdir = gifdirself.imageDim = []self.count = 0if os.path.isdir(gifdir) == False:os.mkdir(gifdir)def infor(self, ):printf(self.gifdir, self.count)def __str__(self, ):return 'gifdir:%s'%self.dirdef append(self, plt):filename = os.path.join(self.gifdir, '%04d.jpg'%self.count)self.count = self.count + 1plt.savefig(filename)self.imageDim.append(Image.open(filename))def appendbox(self, boxid, side=0):filename = os.path.join(self.gifdir, '%04d.jpg'%self.count)self.count = self.count + 1tspsaveimagebox(boxid, filename, side)self.imageDim.append(Image.open(filename))def appendrange(self, rangeid, side=0):filename = os.path.join(self.gifdir, '%04d.jpg'%self.count)self.count = self.count + 1tspsaveimagerange(rangeid, filename, side)self.imageDim.append(Image.open(filename))def save(self, giffile=r'd:\temp\gif1.gif', period=100, last=100):duration = [period] * len(self.imageDim)duration[-1] = lastself.imageDim[0].save(giffile,\save_all=True,\append_images=self.imageDim[1:],\duration=duration,loop=False)self.imageDim = []self.count = 0file_stats = os.stat(giffile)printf('%s size:%5.2fM\a'%(giffile, file_stats.st_size / (1000*1000.0)))def dop2gif(giffile=r'd:\temp\gif1.gif', gifid=0, period=50, last=50):dopfilename = tspgetresourcefile(gifid)if os.path.isfile(dopfilename) == False: return 1filedir = os.path.dirname(dopfilename)filedim = os.listdir(filedir)imageDim = []for f in filedim:imageDim.append(Image.open(os.path.join(filedir, f)))duration = [period] * len(imageDim)duration[-1] = lastimageDim[0].save(giffile,save_all=True,append_images=imageDim[1:],duration=duration,loop=False)printf('Save GIF: %s'%giffile)return 0def dir2gif(giffile=r'd:\temp\gif1.gif', gifdir=r'd:\temp\gif', period=50, last=50):filedir = gifdirfiledim = os.listdir(filedir)if len(filedim) == 0: return 0imageDim = []for f in filedim:imageDim.append(Image.open(os.path.join(filedir, f)))duration = [period] * len(imageDim)duration[-1] = lastimageDim[0].save(giffile,save_all=True,append_images=imageDim[1:],duration=duration,loop=False)printf('Save GIF: %s'%giffile)return 0def filedim2gif(giffile=r'd:\temp\gif1.gif', filedim=[], period=50, last=50):if len(filedim) ==0: return 0imageDim = []for f in filedim:imageDim.append(Image.open(os.path.join(filedir, f)))duration = [period] * len(imageDim)duration[-1] = lastimageDim[0].save(giffile,\save_all=True,\append_images=imageDim[1:],\duration=duration,loop=False)printf('Save GIF: %s'%giffile)return 0def files2gif(giffile=r'd:\temp\gif1.gif', filename=r'd:\temp\gif\0000.jpg', number=0, period=50, last=50):if len(filename) == 0: return 0if number == 0: return 0removeflag = 0if number < 0:number = -numberremoveflag = 1filedir = os.path.dirname(filename)fileext = filename.split('.')[-1]imageDim = []for i in range(number):files = os.path.join(filedir, '%04d.%s'%(i, fileext))imageDim.append(Image.open(files))if removeflag == 1: os.remove(files)durations = [period] * len(imageDim)durations[-1] = lastimageDim[0].save(giffile,save_all=True,append_images=imageDim[1:],duration=durations,loop=False)printf('Save GIF: %s'%giffile)return 0def tempgifdir():gifdir = r'd:\temp\GIF'if os.path.isdir(gifdir) == False:os.mkdir(gifdir)return gifdirfiles = os.listdir(gifdir)for f in files:if os.path.isfile(f):os.remove(os.path.join(gifdir, f))return gifdir

二、相关博文

  与生成GIF文件相关的博文,还可以参见: 如何使用Python语言将测量数据曲线动起来? matplotlib转换成 GIF文件


■ 相关文献链接:

  • 应用在机器学习中的聚类数据集产生方法

  • 如何使用Python语言将测量数据曲线动起来? matplotlib转换成 GIF文件

  • 应用在机器学习中的聚类数据集产生方法

如何生成动态matlibplot动图?相关推荐

  1. ArcGIS中ArcMap时间滑块功能对长时间序列栅格遥感影像进行动态显示并生成视频或动图

      本文介绍基于ArcMap软件,利用时间滑块功能,对大量多时相栅格遥感影像数据进行动态显示,并生成视频或动图的方法.   首先,我们需要在ArcMap软件中新建一个镶嵌数据集,并将全部的多时像遥感影 ...

  2. vue项目将多张图片生成一个gif动图

    当前做项目有一个需求是将多张图片生成一个gif动图的形式 类似下面图片几张图片叠加生成一个gif动图 图片涉及工作隐私,就不公开啦 我们要引入一个gif.js的引入包,但是他没有直接引入的方式,只能从 ...

  3. android 动态工厂,动图工厂下载

    专业的GIF/动图制作软件,你想要的功能都在这里.                                                                 [功能一览]    ...

  4. Python turtle 生成鸡哥动图,以及对鸡哥图片的爬取(附源码,注释)

    大一上学期Python大作业: 简述: 一. python turtle 库绘图,并实现动图效果 (1)篮球召唤阵 (2)铁山靠及打球 (3)哥哥投篮 (4)对鸽鸽的真心 二. 爬虫爬取鸡哥图片 (1 ...

  5. 【图神经网络DGL】GCN在Karate Club上的实战(消息传递范式 | 生成训练可视化动图)

    学习总结 回顾[图神经网络DGL]数据封装和消息传递机制 的数据封装,在做异构图神经网络时,DGL比PyG方便很多(尽管PyG已经支持了异构图Aminer和栗子,但对图结构数据做批处理还是需要自己实现 ...

  6. Python之——生成动态路由轨迹图

    一.scapy简介与安装 scapy( http://www.secdev.org/projects/scapy/)是一个强大的交互式数据包处理程序,它能够对数据包进行伪造或解包,包括发送数据包.包嗅 ...

  7. wex5 生成动态轮播图代码

    这是w文件下的代码 js代码,生成一个数组后,复制一下方法就可以使用 var carousel = that.comp("carousel3");for (var i = 0; i ...

  8. 如何生成webp动图

    一张动态的封面 vs 一张静止的封面 一方面,在观感上动图能给用户更好的体验,一方面也能让用户短时间获取更多的信息,以下文章将记录如何用视频生成自己想要的动图. 方案 1.使用ffmpeg从视频前5秒 ...

  9. gif动图表情包如何制作?教你一键生成gif表情包

    随着网络的普及,gif动图表情包在广大网民中非常流行.那么,gif动图表情包是如何制作的呢? 一般来说,gif动图表情包的制作需要专业的软件工具.常用的软件工具有SOOGIF动图.Adobe Phot ...

最新文章

  1. Ubuntu下,Java中利用JNI调用codeblocks c++生成的动态库的使用步骤
  2. 未知mysql主机怎么办_Mysql如何巧妙的绕过未知字段名详解
  3. 【Android Gradle 插件】Gradle 映射文件 ( settings.gradle 映射为 Settings 类 | build.gradle 映射为 Project 类 )
  4. Exchange Server2013 系列九:常规配置
  5. boost::mp11::mp_clear相关用法的测试程序
  6. Page 56 WPF布局原则
  7. 将数据导入到mysql_Mongodb数据导入到mysql
  8. Eclipse安装aptana
  9. JPA基础(三):搭建JPA开发环境和全局事务介绍
  10. 普通人学python有意义吗-自学Python编程的第一天----------来自苦逼的转行人
  11. 性能测试--jmeter中的HTTP信息头管理器的使用【8】
  12. 30种SQL查询语句优化方法
  13. ffmpeg推流及python管道控制ffmpeg推流
  14. 互联网晚报 | 12月5日 星期日 | 饿了么启用AI技术研发新菜品;搜狐将布局知识直播;《英雄联盟手游》获选苹果年度游戏...
  15. 在ubuntu系统下下载和卸载skype
  16. webapp(WebRoot)目录下的jsp访问不了webapp目录的css文件的问题解决
  17. 数据结构java实验_20172301 《Java软件结构与数据结构》实验一报告
  18. 亚马逊秒杀活动怎么报名?站斧浏览器亚马逊站内促销
  19. 安卓GB28181跨网段语音对讲
  20. 揭秘三位图灵奖得主Hinton、LeCun、Bengio的传奇人生

热门文章

  1. 最好用的嵌入式网络C库、Lua库
  2. Win32API 窗口程序的创建7大步骤
  3. Web前端开发人员和设计师必读文章推荐【系列九】
  4. 修改mysql数据库编码
  5. Web新动力 ——Ajax
  6. myflow.js 工作流类扩展
  7. DOM4J对于XML的用法
  8. Oracle 10GR2+ASM在OEL上的安装(VMware Server 1.0)
  9. 识别、触达、转化、评估!百度云用ABC四招颠覆营销不可能
  10. another app is currently holding the yum lock;waiting for it to exit解决