zoukankan      html  css  js  c++  java
  • 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)
    
    
  • 相关阅读:
    Python学习摘要201802
    机器学习-梯度下降参数调优小结
    用尽洪荒之力学习Flask源码
    Flask类的属性和方法大全
    Flask第三方工具组件介绍
    Flask自带的常用组件介绍
    Centos下部署Flask
    Python Tips阅读摘要
    web程序设计关于我们
    软工实践总结
  • 原文地址:https://www.cnblogs.com/komean/p/10457796.html
Copyright © 2011-2022 走看看