究尽数学Aha数学

使用FFmpeg:图片合成视频

2019-06-04  本文已影响4人  一念一觉一圣人

意欲制作一个数学年表视频:在世界地图上,展示数学历史事件的时间、地点(国家)、人物等;按时间的顺序,在地图上标记事件的发生地,简述事件。

Python作图

# -*- coding:utf-8 -*-

import pygal as gmap
from pygal.style import TurquoiseStyle
import pandas as pd
import os

class MathHistory:
    def __init__(self):
        self.areaCode = {'中国':['cn'],
        '埃及':['eg'],'印度':['in'],'意大利':['it'],
        '法国':['fr'],'德国':['de'],'俄国':['ru'],
        '荷兰':['nl'],'日本':['jp'],'挪威':['no'],'英国':['gb'],
        '瑞士':['sz'],'美国':['us'],'希腊':['gr'],'阿拉伯':['ae'],'欧洲':[('europe', 1)],
        '苏联':['ru','ua','by','ge','am','az'],'奥地利':['at'],'以色列':['il'],'巴比伦':['iq']}

    def save2png(self):
        try:
            df = pd.read_excel('Math.xlsx')
            for index, row in df.iterrows():
                map_chart = gmap.maps.world.World(style=TurquoiseStyle)
                if row['type'] == 'BC':
                    map_chart.title = u'公元前' + str(row['year']) + u'年:' + row['event']
                else:
                    map_chart.title = u'公元' + str(row['year']) + u'年:' + row['event']
                map_chart.add(row['country'], self.areaCode[row['country']])
                for i in range(5):
                    chart_name = '00000' + str(index*5+i) + '.svg'
                    chart_name = 'pic/' + chart_name[-8:]
                    map_chart.render_to_file(chart_name)
                    #map_chart.render_to_png(chart_name)
                break
        except Exception as e:
            print(e)
if __name__=='__main__':
    MathHistory().svg2png()

需要注意,上述国家的代码字典来自pygal的说明文档

使用FFmpeg合成视频

想要了解更多数学内容,请关注公众号:“究尽数学”“究尽中学数学”

上一篇下一篇

猜你喜欢

热点阅读