• 绘制动图,金星木星月亮太阳绕圆


    图💫

    input绘制 行星 木星 太阳 地球 金星💫 地球 月亮各自旋转 1年 角度 360.gif

    在这里插入图片描述

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    import math
    import os
    
    # 设置中文字体
    font_style = '宋体'
    plt.rcParams['font.family'] = font_style
    plt.rcParams['axes.unicode_minus'] = False
    
    # 设置英文字体
    english_fonts = []
    
    font_directory = '/storage/emulated/0/文件/字体大全/'
    
    for root, dirs, files in os.walk(font_directory):
        for file in files:
            if file.endswith('.ttf') or file.endswith('.otf'):
                font_path = os.path.join(root, file)
                try:
                    with open(font_path, 'rb') as f:
                        font_data = f.read()
                        if b'english' in font_data.lower():
                            english_fonts.append(font_path)
                except Exception as e:
                    pass
    
    if len(english_fonts) > 0:
        # 使用第一个可用英语字体
        plt.rcParams['font.sans-serif'] = os.path.splitext(os.path.basename(english_fonts[0]))[0]
    else:
        print('No English fonts available')
    
    def update_points(num, data, line):
        line.set_data(data[..., :num])
        return line,
    
    
    fig, ax = plt.subplots()
    
    theta = np.linspace(0, 2*np.pi, 100)
    a = 1
    b = 2
    x = a * np.cos(theta)
    y = b * np.sin(theta)
    
    data = np.array([x, y])
    
    l, = plt.plot([], [], 'r--')
    plt.xlim(-3, 3)
    plt.ylim(-3, 3)
    plt.xlabel('X')
    plt.ylabel('Y')
    plt.title('行星运动轨迹')
    
    line_ani = animation.FuncAnimation(fig, update_points, 100, fargs=(data, l),
                                       interval=50, blit=True)
    
    # 保存为gif动画
    filepath = '/storage/emulated/0/qpython/planet.gif'
    line_ani.save(filepath, writer='imagemagick')
    
    print(f'动画已保存至 {filepath}')
    
    
    • 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
  • 相关阅读:
    MySQL之优化SELECT语句
    Windows部署Docker
    Vector-valued function
    力扣(104.101)补9.7
    QGIS空间分析项目实战
    STM32 ADC基础知识讲解
    Win9x在Ryzen等新处理器虚拟机抽风的原因及补丁
    十九、【文本编辑器(五)】排版功能
    Mysql 如何模糊匹配后匹配优化
    java毕业设计程序设计类课程的课堂教学效果评价系统Mybatis+系统+数据库+调试部署
  • 原文地址:https://blog.csdn.net/weixin_73675558/article/details/133473055