Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib draw showing nothing

I'm using python's matplotlib to do some contours using contour and contourf functions. They all work fine when using show, but when I try to use draw() inside a method, I get the matplotlib window but not graph. The show() call will be done much later on the code and in a different method, and I would like to show one graph at the moment when it's done with draw(), not having to wait until the much later show(). What I'm doing wrong?

Thanks.

like image 316
Ivan Avatar asked Apr 04 '11 16:04

Ivan


1 Answers

Have you turned interactive mode on using ion()? The following works for me on OSX, using the Tk backend and running from the shell's command line:

import matplotlib.pyplot as plt

plt.ion()
plt.figure()
for i in range(10):
    plt.plot([i], [i], 'o')
    plt.draw()
raw_input("done >>")  

That is, as it does each loop, you see the plot change (i.e., it gets redrawn) as each point is added. Here, btw, if I instead call plt.ioff(), I don't see the figure or any updates.

like image 104
tom10 Avatar answered Oct 12 '22 18:10

tom10