Tad
Tad

Reputation: 838

Updating plot without having to close the window with the plot

I have a function which creates a plot. That function is called inside a loop which updates information about objects to be drawn. After the call to draw() I ask the user to press a key. The problem I am encountering is that when I execute the program, the plot appears in a new window and the code execution stops until I close that window. It is only then when the prompt for user input is executed. How can I do it so that i don't need to close the plot, but just press enter and the plot gets updated automatically then without me having to close the window? Thank you!

def draw(self):
        #### more code

        fig, ax = plt.subplots()
        im = ax.imshow(p, extent=[x.min(), x.max(), y.min(), y.max()])
        ax.quiver(x[skip], y[skip], dx[skip], dy[skip])

        fig.colorbar(im)
        ax.set(aspect=1, title='Impulse world')

        print self.player

        circle = plt.Circle((self.player.pos_x, self.player.pos_y), radius=25, fc='w')
        plt.gca().add_patch(circle)

        #### more code

        plt.show()


#inside a loop
draw()
raw_input("press enter to continue...")

Upvotes: 0

Views: 1285

Answers (1)

user3996333
user3996333

Reputation:

Did you try with plt.show(block=False) ?

Upvotes: 2

Related Questions