Python:GUI-绘图,从实时GUI中的像素读取

Python:GUI-绘图,从实时GUI中的像素读取,python,numpy,user-interface,matplotlib,arduino,Python,Numpy,User Interface,Matplotlib,Arduino,我正在做一个项目。我是新手,室友是软件工程师,建议我在这个项目中使用python。我的问题列在下面。首先,这里是我试图实现的目标的概述 项目概述: 可寻址RGB led矩阵阵列,例如,50个led x 50个led(250个 LED)。led矩阵连接到arduino并由其运行 将从分散的服务器接收矩阵的模式信息 节目。(稍后我们将讨论arduino的功能) 该程序的目的是生成和发送模式信息 对于每个可寻址的LED,都指向arduino 该程序将承载一个GUI,以改变和可视化 实时输出或当前矩阵颜

我正在做一个项目。我是新手,室友是软件工程师,建议我在这个项目中使用python。我的问题列在下面。首先,这里是我试图实现的目标的概述

项目概述:

可寻址RGB led矩阵阵列,例如,50个led x 50个led(250个 LED)。led矩阵连接到arduino并由其运行 将从分散的服务器接收矩阵的模式信息 节目。(稍后我们将讨论arduino的功能)

该程序的目的是生成和发送模式信息 对于每个可寻址的LED,都指向arduino

该程序将承载一个GUI,以改变和可视化 实时输出或当前矩阵颜色映射和图案(即打开/关闭 频闪效果,打开/关闭淡入效果)。然后程序将读取 从gui生成并转换要发送到的RGB值 阿杜伊诺

这就是我所处的位置,我需要指导。到目前为止,我的重点是在继续本项目的下一部分之前让GUI正常工作

我使用matplotlib希望我可以创建一个50x50平方(或像素)的绘图,并保留对每个点的值的控制。理想情况下,我可以每秒绘制30次绘图,或者无论绘制多少次,这样它看起来都是“实时”更新的

以下是一些示例代码,您可以更好地了解我要实现的目标:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import cm
from numpy.random import random

fig = plt.figure()
matrix = random((50,50))
plt.imshow(matrix, interpolation='nearest', cmap=cm.spectral)


def update(data):
    print("IN UPDATE LOOP")
    matrix = random((50,50))
    return matrix

def data_gen():
    print("IN DATA_GEN LOOP")
    while True: yield np.random.rand(10)


ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)
plt.imshow(matrix, interpolation='nearest', cmap=cm.spectral)
plt.show()
plt.draw()

网格不会更新,不知道为什么


为什么我的网格没有更新?

忽略前两个问题,因为它们不是真正的主题,代码的问题是您从来没有实际更新过图像。这应该在动画功能中完成

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import cm
from numpy.random import random

fig = plt.figure()
matrix = random((50,50))
im = plt.imshow(matrix, interpolation='nearest', cmap=cm.Spectral)

def update(data):
    im.set_array(data)

def data_gen():
    while True: 
        yield random((50,50))

ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)

plt.show()

美丽的!这正是我需要的。。。基本上回答了我所有的问题。