简化代码
png_list=[]
for i in glob.glob(r"C:\Users\Administrator\Desktop\新建文件夹\图片/*.png"):#存放照片的文件夹
png_list.append(imageio.imread(i) )
imageio.mimsave("try.gif",png_list,'GIF',duration=0.1)
# coding=utf-8
import math
import tushare as ts
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import talib
import pandas as pd
import datetime
matplotlib.rcParams['axes.unicode_minus']=False
plt.rcParams['font.sans-serif']=['SimHei']
import numpy as np
import imageio
import datetime
def f1():
fig, ax = plt.subplots()
size = 0.3
vals = np.array([[20., 22.], [20., 22.], [20., 22.],[20., 22.]])
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(4)*2)
inner_colors = cmap([1, 2, 5, 6, 9, 10])
ax.pie(vals.sum(axis=1), radius=1, colors=outer_colors,
wedgeprops=dict(width=size, edgecolor='w'))
plt.text(0.5, 0.5, '股票')
plt.text(-0.65, -0.65, '现金')
plt.text(-0.66, 0.6, '债券')
plt.text(0.55, -0.55, '商品')
ax.annotate('复苏期',
xy=(1.2, -0.6), xycoords='data',
xytext=(0, 112), textcoords='offset points',
arrowprops=dict(facecolor='black', shrink=11),
horizontalalignment='right', verticalalignment='bottom')
ax.set(aspect="equal", title='')
plt.show()
def f2():
fig, ax = plt.subplots()
size = 0.3
vals = np.array([[20., 22.], [20., 22.], [20., 22.],[20., 22.]])
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(4)*2)
inner_colors = cmap([1, 2, 5, 6, 9, 10])
ax.pie(vals.sum(axis=1), radius=1, colors=outer_colors,
wedgeprops=dict(width=size, edgecolor='w'))
plt.text(0.5, 0.5, '股票')
plt.text(-0.65, -0.65, '现金')
plt.text(-0.66, 0.6, '债券')
plt.text(0.55, -0.55, '商品')
ax.annotate('过热期',
xy=(-0.65, -1.2), xycoords='data',
xytext=(152, 0), textcoords='offset points',
arrowprops=dict(facecolor='black', shrink=11),
horizontalalignment='right', verticalalignment='bottom')
ax.set(aspect="equal", title='')
plt.show()
def f4():
fig, ax = plt.subplots()
size = 0.3
vals = np.array([[20., 22.], [20., 22.], [20., 22.],[20., 22.]])
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(4)*2)
inner_colors = cmap([1, 2, 5, 6, 9, 10])
ax.pie(vals.sum(axis=1), radius=1, colors=outer_colors,
wedgeprops=dict(width=size, edgecolor='w'))
plt.text(0.5, 0.5, '股票')
plt.text(-0.65, -0.65, '现金')
plt.text(-0.66, 0.6, '债券')
plt.text(0.55, -0.55, '商品')
ax.annotate('衰退期',
xy=(0.65, 1.2), xycoords='data',
xytext=(-122, 0), textcoords='offset points',
arrowprops=dict(facecolor='black', shrink=11),
horizontalalignment='right', verticalalignment='bottom')
ax.set(aspect="equal", title='')
plt.show()
def f3():
fig, ax = plt.subplots()
size = 0.3
vals = np.array([[20., 22.], [20., 22.], [20., 22.],[20., 22.]])
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(4)*2)
inner_colors = cmap([1, 2, 5, 6, 9, 10])
ax.pie(vals.sum(axis=1), radius=1, colors=outer_colors,
wedgeprops=dict(width=size, edgecolor='w'))
plt.text(0.5, 0.5, '股票')
plt.text(-0.65, -0.65, '现金')
plt.text(-0.66, 0.6, '债券')
plt.text(0.55, -0.55, '商品')
ax.annotate('滞涨期',
xy=(-1.2, 0.66), xycoords='data',
xytext=(0, -122), textcoords='offset points',
arrowprops=dict(facecolor='black', shrink=11),
horizontalalignment='right', verticalalignment='bottom')
ax.set(aspect="equal", title='')
plt.show()
def f1():
fig, ax = plt.subplots()
size = 0.7#控制外圈大小
vals = np.array([[20., 22.], [20., 22.], [20., 22.],[20., 22.]])
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(4)*2)
inner_colors = cmap([1, 2, 5, 6, 9, 10])
ax.pie(vals.sum(axis=1), radius=1, colors=outer_colors,
wedgeprops=dict(width=size, edgecolor='w'))
plt.text(0.45, 0.6, '股票')
plt.text(-0.68, -0.65, '滞涨期')
plt.text(-0.66, 0.6, '债券')
plt.text(-0.66, 0.45, '衰退期')
plt.text(0.35, -0.65, '过热期')
plt.text(0.41, -0.50, '商品')
plt.text(0.40, 0.45, '复苏期')
plt.text(-0.65, -0.50, '现金')
ax.annotate('',
xy=(.35, 0.5), xycoords='data',
xytext=(-50, 0), textcoords='offset points',
arrowprops=dict(facecolor='black', shrink=11),
horizontalalignment='right', verticalalignment='bottom')
ax.set(aspect="equal", title='')
plt.savefig('t4.png',dpi=500)
依次画出四张图
#!/bin/python3
import imageio
import glob
import re
def create_gif(image_list, gif_name):
frames = []
for image_name in image_list:
frames.append(imageio.imread(image_name))
# Save them as frames into a gif
imageio.mimsave(gif_name, frames, 'GIF', duration = 0.000001)
return
def find_all_png():
png_filenames = glob.glob(r"C:\Users\Administrator\Desktop\新建文件夹\图片/*.png")#存放图片的文件夹
buf=[]
for png_file in png_filenames:
buf.append(png_file)
return buf
if __name__ == '__main__':
buff = find_all_png()
create_gif(buff,'created_gif.gif' )