使用Python通过命令行进行交互式绘图 [英] Interactive plotting with Python via command line

查看:1060
本文介绍了使用Python通过命令行进行交互式绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python和numpy和matplotlib库做一些数据分析和绘图,并查看我的情节,相应地调整我的代码等。所以我需要能够检查的情节。但是,从命令行运行脚本会使图形立即弹出,然后立即消失。另一个答案建议在程序结尾添加一个 raw_input(text here)行,强制python等待输入并保持打开。这保持绘图窗口为我打开,但实际绘图消失,我只是得到一个空的灰色图窗口,而python等待输入。

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.

我运行 MAC OS X 10.8.3 ,并使用 terminal v2.3 和我的python安装 python 2.7.3

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。

Use plt.show at the end of your code

这篇关于使用Python通过命令行进行交互式绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆