使用matplotlib在Spyder中进行交互式(?)绘图 [英] Interactive(?) plotting in Spyder with matplotlib

查看:830
本文介绍了使用matplotlib在Spyder中进行交互式(?)绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Matlab迁移到Python,却无法弄清楚如何在Spyder IDE中进行交互式(?)绘图.我的测试代码如下所示.使用.ion()时,什么都不会发生,我快速绘制了一个图形,然后窗口立即关闭并吐出我的Hello.如果没有.ion(),则会正确绘制图形,但脚本会挂起并且不会吐出Hello,直到我手动关闭图形窗口.我希望该脚本像Matlab脚本那样运行,并绘制我要求它的各种图形,同时进行任何计算并将输出放在terminal(?)窗口中.

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.

我尝试在ipython中一次输入一行,它似乎可以工作,但是我宁愿以脚本表格式工作,我可以在各行之间来回调整代码.

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.

如果有帮助,我正在Windows 7中工作.我安装了python(x,y)并从那里启动spyder(spyder版本2.1.9).我已经看到一些类似的问题,但我无法解决此问题.在我看来,有人说ipythons最新版本与spyder不兼容,但随后我看到另一则帖子说无论如何都应支持交互式绘图.谢谢您的帮助!如果有人有替代环境,我可以用来模仿同样可行的matlab行为,那么我真的是Python的新手.

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")

推荐答案

运行配置应设置为在当前的Python或IPython解释器中执行,默认情况下,它允许进行交互式绘图.如果将解释器设置为在新的专用Python解释器中执行 ,则必须选择在执行后与Python解释器进行交互.

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.

这篇关于使用matplotlib在Spyder中进行交互式(?)绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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