0

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...")
Tad
  • 838
  • 2
  • 11
  • 22
  • Duplicate? http://stackoverflow.com/q/5050988/1914052 – jwalker Sep 07 '14 at 15:44
  • I have looked at http://stackoverflow.com/questions/5050988/in-matplotlib-is-there-a-way-to-pop-up-a-figure-asynchronously and my code does print "doing something else" but raw_input is still blocked. Do you know how to resolve this? – Tad Sep 07 '14 at 16:34
  • nvm, resolved by running it in ipython. – Tad Sep 07 '14 at 16:36

1 Answers1

2

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