• python绘制动态图


    1、需要注意的问题

    • 解决 MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented warnings.warn(str, mplDeprecation 问题
    import warnings
    warnings.filterwarnings("ignore",".*GUI is implemented.*")
    
    • 运行结束时,闪退,使用
    plt.pause(0)
    

    2、具体代码test.py:

    import matplotlib.pyplot as plt
    from matplotlib.patches import Circle
    import numpy as np
    import math
    
    import warnings
    # 解决(MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented warnings.warn(str, mplDeprecation)
    warnings.filterwarnings("ignore",".*GUI is implemented.*")
    
    
    fig = plt.figure()
    # 连续性的画图
    ax = fig.add_subplot(1, 1, 1)
    # 设置图像显示的时候XY轴比例
    ax.axis("equal")
    # 开启一个画图的窗口
    plt.ion()
    print('开始仿真')
    try:
        for i in range(20):
            x = np.random.randn()
            y = np.random.randn()
            if x < 0.5:
                ax.scatter(x, y, c='r', marker='v')  # 散点图
            else:
                ax.scatter(x, y, c='b', marker='.')  # 散点图
            plt.axvline(0.5)  # 画出竖线 (y=0.5)
            plt.axvline(-0.5)  # 画出竖线 (y=-.5)
            # 停顿时间
            plt.pause(0.1)
    except Exception as err:
        print(err)
    # 防止运行结束时闪退
    plt.pause(0)
    
    
  • 相关阅读:
    Java Jsch SFTP 递归下载文件夹
    spring-jms,spring-boot-starter-activemq JmsTemplate 发送方式
    Spring Boot 入门之消息中间件篇(转发)
    Springboot websocket使用
    FinalCutPro快捷键
    基本CSS布局三
    As Simple as One and Two
    Game of Credit Cards
    WOW Factor
    Lose it!
  • 原文地址:https://www.cnblogs.com/komean/p/10457796.html
Copyright © 2020-2023  润新知