简体   繁体   中英

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.ion()
plt.figure("Test Figure")
plt.plot(xspace[:],vals[:,50])

raw_input("press key to exit")

在代码末尾使用plt.show

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM