Matplotlib python show() returns immediately

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()

Leave a Comment