简体   繁体   English

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

[英]Interactive(?) plotting in Spyder with matplotlib

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

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. 我尝试在ipython中一次键入一行,它似乎可以工作,但是我宁愿以脚本表格式工作,我可以在行之间来回调整代码。

I'm working in windows 7 if that helps. 如果有帮助,我正在Windows 7中工作。 I installed python(x,y) and am launching spyder from there (spyder version 2.1.9). 我安装了python(x,y)并从那里启动spyder(spyder版本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. 在我看来,有人说ipythons最新版本与spyder不兼容,但后来我看到另一则帖子说无论如何都应支持交互式绘图。 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. 如果有人有替代环境,我可以用来模仿同样可行的matlab行为,那么我真的是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. 在当前的Python或IPython解释器中 ,运行配置应设置为Execute,默认情况下允许交互式绘图。 If the interpreter is set to Execute in a new dedicated Python interpreter then Interact with the Python interpreter after execution must be selected. 如果在新的专用Python解释器中将解释器设置为Execute,则必须选择执行后与Python解释 进行交互

in my case, these were the default settings in spyder however it still didn't show the plot until I typed: %matplotlib inline 在我的情况下,这些是spyder中的默认设置,但是直到我键入后,它仍然没有显示图: %matplotlib inline

Not sure if this is helpful but thought of sharing here. 不知道这是否有帮助,但想在这里分享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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