Python 如何在macOS上的PyCharm中使用Matplotlib.animation.FuncAnimation显示动画图形?

Python 如何在macOS上的PyCharm中使用Matplotlib.animation.FuncAnimation显示动画图形?,python,macos,matplotlib,pycharm,Python,Macos,Matplotlib,Pycharm,我正在尝试使用matplotlib.animation.FuncAnimation显示动画图形(而不是通过终端)。我正在macOS 10.14.6上使用PyCharm Professional 2019.2 我还没有找到任何适合macOS上PyCharm的解决方案 我试过几件事: 使用FuncAnimate 添加 如中所述。这会导致我的PyCharm崩溃,并将我带到macOS登录屏幕 import datetime as dt import matplotlib.pyplot as plt im

我正在尝试使用matplotlib.animation.FuncAnimation显示动画图形(而不是通过终端)。我正在macOS 10.14.6上使用PyCharm Professional 2019.2

我还没有找到任何适合macOS上PyCharm的解决方案

我试过几件事:

  • 使用
    FuncAnimate

  • 添加

  • 如中所述。这会导致我的PyCharm崩溃,并将我带到macOS登录屏幕

    import datetime as dt
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    
    # Create figure for plotting
    figure = plt.figure()
    axis = figure.add_subplot(1, 1, 1)
    xs = []
    ys = []
    
    
    # This function is called periodically from FuncAnimation
    def animate(i, xs, ys):
        # Add x and y to lists
        xs.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
        ys.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
    
        # Limit x and y lists to 20 items
        xs = xs[-20:]
        ys = ys[-20:]
    
        # Draw x and y lists
        axis.clear()
        axis.plot(xs, ys)
    
        # Format plot
        plt.xticks(rotation=45, ha='right')
        plt.subplots_adjust(bottom=0.30)
        plt.title('Data over Time')
        plt.ylabel('Data')
    
    
    # Set up plot to call animate() function periodically
    ani = animation.FuncAnimation(figure, animate, fargs=(xs, ys), interval=1000)
    plt.show()
    
    这段代码只是简单地基于时间(两个轴)绘制一个线性函数

    通过终端进行编译时,图形工作正常。PyCharm出于某种原因不想绘制它。macOS有什么解决方案吗?

    看起来它还在PyCharm中。
    import datetime as dt
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    
    # Create figure for plotting
    figure = plt.figure()
    axis = figure.add_subplot(1, 1, 1)
    xs = []
    ys = []
    
    
    # This function is called periodically from FuncAnimation
    def animate(i, xs, ys):
        # Add x and y to lists
        xs.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
        ys.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
    
        # Limit x and y lists to 20 items
        xs = xs[-20:]
        ys = ys[-20:]
    
        # Draw x and y lists
        axis.clear()
        axis.plot(xs, ys)
    
        # Format plot
        plt.xticks(rotation=45, ha='right')
        plt.subplots_adjust(bottom=0.30)
        plt.title('Data over Time')
        plt.ylabel('Data')
    
    
    # Set up plot to call animate() function periodically
    ani = animation.FuncAnimation(figure, animate, fargs=(xs, ys), interval=1000)
    plt.show()