Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在kivy中使用matplotlib动画_Python_Animation_Matplotlib_Kivy - Fatal编程技术网

Python 如何在kivy中使用matplotlib动画

Python 如何在kivy中使用matplotlib动画,python,animation,matplotlib,kivy,Python,Animation,Matplotlib,Kivy,我想展示加速度传感器数据的实时图表。Kivy是框架,matplotlib应用于绘图。 我可以轻松地在我的应用程序屏幕中集成静态绘图,但是我没有成功地使用matplotlib动画方法。我该怎么做?根据我发现的一个例子(不是为kivy制作的),下面是我目前为止的代码 class FigGraphLive(BoxLayout): def __init__(self, **kwargs): super(FigResultPropGraphLive, self).__init__(**kwarg

我想展示加速度传感器数据的实时图表。Kivy是框架,matplotlib应用于绘图。 我可以轻松地在我的应用程序屏幕中集成静态绘图,但是我没有成功地使用matplotlib动画方法。我该怎么做?根据我发现的一个例子(不是为kivy制作的),下面是我目前为止的代码

class FigGraphLive(BoxLayout):

def __init__(self, **kwargs):
    super(FigResultPropGraphLive, self).__init__(**kwargs)

    fig = Figure(figsize=(3, 1), facecolor='none', dpi=90)
    ax = fig.add_subplot(111)
    ax.set_axis_bgcolor('none')
    ax.spines['bottom'].set_color('white')
    ax.spines['top'].set_color('white')
    ax.spines['left'].set_color('white')
    ax.spines['right'].set_color('white')
    xa = ax.xaxis                  
    ya = ax.yaxis
    xa.set_tick_params(labelcolor='white')
    xa.set_tick_params(color='white')
    ya.set_tick_params(labelcolor='white')
    ya.set_tick_params(color='white')

    self.valx = np.zeros(0)
    self.valy = np.zeros(0)
    self.valz = np.zeros(0)
    self.time = np.zeros(0)
    plxax = ax.plot(self.time, self.valx, color='blue', label='X-Axis')
    plyax = ax.plot(self.time, self.valy, color='red', label='Y-Axis')
    plzax = ax.plot(self.time, self.valz, color='green', label='Z-Axis')

    leg = ax.legend()
    leg.get_frame().set_alpha(0.4)

    self.plxmin = 0.0
    self.plxmax = 10.0
    self.plx = 0.0

    simulation = mplanimation.FuncAnimation(fig, self.updateGraph, blit=False, frames=200, interval=50, repeat=False)

    figcanvas = FigureCanvas(fig)
    figcanvas.draw()

    self.create_plot(figcanvas)

def updateGraph(self):
    self.valx = np.append(self.valx, np.random.rand() * 4)
    self.valy = np.append(self.valx, np.random.rand() * 4)
    self.valz = np.append(self.valx, np.random.rand() * 0.5)

    self.plx += 0.05

    if self.plx >= self.plxmax - 1.00:
        plxax.axes.set_xlim(self.plx - self.plxmax + 1.0, x + 1.0)
        plyax.axes.set_xlim(self.plx - self.plxmax + 1.0, x + 1.0)
        plzax.axes.set_xlim(self.plx - self.plxmax + 1.0, x + 1.0)

    return plxax, plyax, plzax

def create_plot(self, figcanvas):
    self.add_widget(figcanvas)

您可以使用kivy garden的matplotlib集成示例:



另一种选择是,在init.py文件中嵌入动画演示。

也许我不明白,但在这里给出的示例中似乎没有使用matplotlib动画的方法。我没有问题,包括图形本身,但动画:-)@jonnny也许这一个会更好:,只需运行init.py,演示中有一个动画正弦。