Ivan
Ivan

Reputation: 20101

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.

Upvotes: 6

Views: 10842

Answers (2)

tom10
tom10

Reputation: 69182

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.

Upvotes: 7

dfb
dfb

Reputation: 13289

IIRC ,You should be able call fig.show() multiple times. Also, check out using ipython (ipython -pylab) and http://matplotlib.sourceforge.net/users/shell.html

Upvotes: 2

Related Questions