Interactive plotting with Python via command line


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.figure("Test Figure")

raw_input("press key to exit")
4/13/2013 7:28:54 PM

Accepted Answer

Use at the end of your code.

3/7/2017 4:59:13 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow