[Python] How to leave matplotlib figure opened after script ends?

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose I have the following script plotting a graph for me:

    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import numpy as np

    img = mpimg.imread('stinkbug.png')
    #circle = plt.Circle((0, 0), radius=0.5, fc='y')
    circle = plt.Circle((0, 0), radius=100, fill=False, color='b')

    fig, ax = plt.subplots()
    ax.imshow(img)
    ax.add_artist(circle)
    fig.show()
    pass


    Unfortunately, the figure closes after the script ends.

    How to prevent that?

    UPDATE

    If it is impossible for the figure to survive the script, then what is the reason for it? What is the connection between the figure and the script?

    Continue reading...

Compartilhe esta Página