How to update a plot in matplotlib?

后端 未结 7 1765
不思量自难忘°
不思量自难忘° 2020-11-22 02:11

I\'m having issues with redrawing the figure here. I allow the user to specify the units in the time scale (x-axis) and then I recalculate and call this function plots

相关标签:
7条回答
  • 2020-11-22 03:11

    I have released a package called python-drawnow that provides functionality to let a figure update, typically called within a for loop, similar to Matlab's drawnow.

    An example usage:

    from pylab import figure, plot, ion, linspace, arange, sin, pi
    def draw_fig():
        # can be arbitrarily complex; just to draw a figure
        #figure() # don't call!
        plot(t, x)
        #show() # don't call!
    
    N = 1e3
    figure() # call here instead!
    ion()    # enable interactivity
    t = linspace(0, 2*pi, num=N)
    for i in arange(100):
        x = sin(2 * pi * i**2 * t / 100.0)
        drawnow(draw_fig)
    

    This package works with any matplotlib figure and provides options to wait after each figure update or drop into the debugger.

    0 讨论(0)
提交回复
热议问题