How to create real time graph in kivy?

gigahex picture gigahex · Apr 3, 2014 · Viewed 22k times · Source

I want to create a real time graph in kivy. How can i achieve that? I m new to kivy. Please help me.

Answer

BlueDog picture BlueDog · Jun 26, 2016

define your plot

e.g.

plot = MeshLinePlot(color=next(colors))

define graph

e.g.

graph = Graph(
    xlabel='Iteration',
    ylabel='Value',
    x_ticks_minor=1,
    x_ticks_major=5,
    y_ticks_major=1,
    y_grid_label=True,
    x_grid_label=True,
    padding=5,
    xlog=False,
    ylog=False,
    x_grid=True,
    y_grid=True,
    ymin=0,
    ymax=11,
    **graph_theme)

update graph and update x axis:

e.g.

    def update_xaxis(self,*args):
        global graph
        global cnt
        graph.xmin = cnt - 50
        graph.xmax = cnt

    def update_points(self, *args):
        global i
        global MYLIST
        global cnt

        #self.plot.points = [(i,i)]
        self.plot.points = [z for z in MYLIST]

call a Clock

e.g.

        Clock.schedule_interval(self.update_points, 1/60.)
        Clock.schedule_interval(self.update_xaxis, 1/60.)

and add the widget:

        b.add_widget(graph)

I hope I have not forgotten anything. It gives you running graph with kivy Garden.