Matplotlib python show() returns immediately

后端 未结 5 1205
梦毁少年i
梦毁少年i 2020-12-09 01:29

I have a simple python script which plots some graphs in the same figure. All graphs are created by the draw() and in the end I call the show() function to block.

T

5条回答
  •  眼角桃花
    2020-12-09 02:22

    I had this same problem, and it was caused by calling show() on the Figure object instead of the pyplot object.

    Incorrect code. Causes the graph to flash on screen for a brief instant:

        import matplotlib.pyplot as plt
    
        x = [1,2,3]
        y = [5,6,7]
    
        fig = plt.figure()
        plt.plot(x, y)
    
        fig.show()
    

    Last line should be as follows to show the graph until it is dismissed:

        plt.show()
    

提交回复
热议问题