python交互式绘图_使用matplotlib在Spyder中进行交互式(?)绘图

本文档介绍了如何在Spyder IDE中使用matplotlib进行交互式绘图。作者遇到的问题是,当运行代码时,图形窗口会瞬间关闭或者脚本会挂起。解决方案是设置运行配置为“在当前Python或IPython解释器中执行”,这将允许交互式绘图。如果解释器设置为“在新的专用Python解释器中执行”,则必须选择“在执行后与Python解释器交互”选项。
摘要由CSDN通过智能技术生成

I am trying to migrate over to Python from Matlab and can't figure out how to get interactive(?) plotting working within the Spyder IDE. My test code is shown below. With the .ion() nothing happens, I get a quick flash of a figure being drawn then the window instantly closes and spits out my Hello. Without the .ion() the figure is drawn correctly but the script hangs and doesn't spit out Hello until I manually close the figure window. I would like the script to run like a matlab script would and plot the various figures I ask it to while chugging along any computations and putting the output on the terminal(?) window.

I tried typing out the lines one at a time in ipython and it seemed to work but I would much rather work in a script sheet format where I can go back and forth between lines tweaking code.

I'm working in windows 7 if that helps. I installed python(x,y) and am launching spyder from there (spyder version 2.1.9). I have seen some similar-ish questions asked but I wasn't able to solve this problem. It seemed to me that someone said ipythons latest version is not compatible with spyder but then I saw another post that said interactive plotting should be supported regardless. Thanks for the help! If anyone has alternative environments I could use to mimick matlab behaviour that would work too, I'm really new to Python.

import matplotlib.pylab as plt

plt.ion()

plt.plot([1,2,3])

plt.show()

plt.ylabel('This is an axis')

print ("Hello")

解决方案

The run configuration should be set to Execute in current Python or IPython interpreter which by default allows for interactive plotting. If the interpreter is set to Execute in a new dedicated Python interpreter then Interact with the Python interpreter after execution must be selected.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值