21

I am trying to use Python and the numpy and matplotlib libraries to do some data analysis and plotting and view my plots, adjust my code accordingly etc. So I need to be able to examine the plot. However, running the script from the command line causes the figure to pop up momentarily then instantly disappear. Another answer suggested to add a raw_input("text here") line at the end of the program to force python to wait for input and hold the plots open. This does hold the plot windows open for me but the actual plots disappear and I just get an empty gray figure window while python waits for input.

I'm running MAC OS X 10.8.3 and using the terminal v2.3 and my python installation is python 2.7.3

import matplotlib.pylab as plt
import numpy as np

[ .. bunch of calculations .. ]

plt.ion()
plt.figure("Test Figure")
plt.plot(xspace[:],vals[:,50])

raw_input("press key to exit")
3
  • 8
    Are you aware of IPython? It's wonderful for interactive computing, including plotting, both from its shells and notebook. Commented Apr 13, 2013 at 19:42
  • 2
    Two years later and I am exclusively using iPython now. Thanks for the suggestion @jorgeca Commented Dec 17, 2015 at 16:15
  • Absolutely, I'm glad it helped. Thanks for the update :) Commented Dec 17, 2015 at 18:29

1 Answer 1

46

Use plt.show at the end of your code.

Sign up to request clarification or add additional context in comments.

1 Comment

Added plt.show() and started using IPython as suggested by jorgeca and everything works fine now, thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.