Continuous 3D plotting (i.e. figure update) using python-matplotlib?

前端 未结 3 870
温柔的废话
温柔的废话 2021-01-02 07:20

I have a simulation which calculates surface data for each iteration of the simulation. I would like to continuously plot that data as a surface plot to the same window (upd

3条回答
  •  误落风尘
    2021-01-02 07:42

    I had a similar problem and this worked for me:

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    plt.ion()
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    for k in xrange(0,X_range):
        ax.plot(x_input, y_input, z_input)
        plt.draw()
        plt.pause(0.02)
        ax.cla()
    

    For you, I'd imagine the solution be something similar to the top answer except replacing time.sleep() with plt.pause(), which would finish the drawing the figure before sleeping.

提交回复
热议问题