安装了 python 3.x 的 Rodeo 实时绘图

real time plot in Rodeo with python 3.x installed

我正在尝试遵循一些生成实时绘图的指南,例如:real-time plotting in while loop with matplotlib and http://thread.gmane.org/gmane.comp.python.matplotlib.general/35705

不过,我相信示例代码是用 python 2.7 编译的。当我尝试编译我的时,我没有看到正在更新的实时绘图。是因为python3不支持吗?还是我错过了图书馆之类的东西?只有当我停止 while 循环时,我才能看到绘制的最后一个值。我正在使用 Rodeo 作为我的 IDE;这会阻止我查看实时情节吗?

import serial 
import numpy as np
import matplotlib.pyplot as plt

def plotlive():
    plt.plot(ard_dat,'o')
    plt.xlabel('count', fontsize=12)
    plt.ylabel('reading', fontsize=12)
    plt.legend(loc='upper right')
ard_dat=[]
plt.ion()
cnt=0
arduinoSerialData = serial.Serial('com5',9600)

while True:
    while (arduinoSerialData.inWaiting()==0):
        pass 

        srdata = arduinoSerialData.readline()
        try:
            intstrdata = int(srdata)
        except ValueError:
            pass 
        ard_dat.append(intstrdata)
        drawnow(plotlive)
        plt.pause(.00001) 
        cnt+=1
        if (cnt>50):
            ard_dat.pop(0)

代码中没有特定的 python 2 或 3 命令,因此您可以将其排除在等式之外。

我不推荐使用 drawnow。而是直接调用 plotlive()。然而,这只是一个建议,因为 drawnow 是一个非常无用的包,但它不会阻止代码 运行ning。

假设连续剧工作正常,问题中的代码在 运行 作为脚本时应该会产生一个更新图。

重点是:Rodeo不能制作动画看到这个问题:https://github.com/yhat/rodeo/issues/488 原因是它使用了类似笔记本的输出机制。在 Jupyter notebook 中,您实际上可以将后端设置为交互模式(%matplotlib tk%matplotlib notebook),这在 Rodeo 中显然是不可能的。

Rodeo 似乎也没有选择 运行 一些代码作为其 IDE 之外的 python 脚本。因此,我们的想法是要么使用不同的 IDE,要么至少使用 Rodeo 之外的 运行 动画。