Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create real time graph in kivy?

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

like image 419
gigahex Avatar asked Apr 03 '14 08:04

gigahex


People also ask

Can I use Matplotlib in KIVY?

Adding matplotlib to a kivy app is pretty easy, we'll use kivy_garden and it'll be a piece of cake!

What is KivyMD?

KivyMD is a collection of Material Design widgets for use with Kivy, a GUI framework for making mobile applications. It is similar to the Kivy framework but provides a more attractive GUI.

Why KIVY is used in Python?

Kivy is a graphical user interface opensource Python library that allows you to develop multi-platform applications on Windows, macOS, Android, iOS, Linux, and Raspberry-Pi. In addition to the regular mouse and keyboard inputs, it also supports multitouch events.


2 Answers

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.

like image 82
BlueDog Avatar answered Nov 04 '22 09:11

BlueDog


There is a graph widget in the kivy garden. You can read about using garden widgets in kivy's documentation.

like image 37
inclement Avatar answered Nov 04 '22 09:11

inclement