[英]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. 我正在尝试使用Python和numpy和matplotlib库来做一些数据分析和绘图并查看我的图,相应地调整我的代码等等。所以我需要能够检查一下情节。 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. 另一个答案建议在程序末尾添加一个
raw_input("text here")
行,以强制python等待输入并保持打开图。 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. 这确实为我打开了绘图窗口,但实际绘图消失了,我只是得到一个空的灰色图形窗口,而python等待输入。
I'm running MAC OS X 10.8.3 and using the terminal v2.3 and my python installation is python 2.7.3 我正在运行MAC OS X 10.8.3并使用终端v2.3 ,我的python安装是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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.